From 85ba5bbb11eddb2eaa28f86c3552322d15ce7443 Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Tue, 22 Jun 2021 12:52:12 +0200 Subject: [PATCH] Close tab when middle click --- .../bytecode/club/bytecodeviewer/gui/TabbedPane.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/TabbedPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/TabbedPane.java index 0db652c8..d02057fd 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/TabbedPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/TabbedPane.java @@ -94,6 +94,18 @@ public class TabbedPane extends JPanel { } }; + this.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON2) { + final int i = pane.indexOfTabComponent(TabbedPane.this); + if (i != -1) { + pane.remove(i); + } + } + } + }); + this.add(label); // add more space between the label and the button label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));