Skip to content

Commit

Permalink
Add "close on middle mouse click on the tab" support
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidePastore committed Nov 7, 2015
1 parent acd511f commit fcee004
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import javax.swing.JComponent
import javax.swing.JMenu
import javax.swing.JMenuItem
import javax.swing.JPopupMenu
import javax.swing.SwingUtilities
import javax.swing.ToolTipManager
import javax.swing.event.ChangeEvent
import java.awt.BorderLayout
Expand All @@ -31,7 +32,6 @@ import javax.swing.ImageIcon
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JTabbedPane
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.awt.event.MouseListener

Expand Down Expand Up @@ -70,7 +70,7 @@ class TabbedPanel extends JPanel implements PreferencesChangeListener {
}
}
ToolTipManager.sharedInstance().registerComponent(tabPanel)
tabPanel.addMouseListener(new MouseAdapter() {
tabPanel.addMouseListener(new MouseListener() {
void mousePressed(MouseEvent e) { showPopupTabMenu(e) }
void mouseReleased(MouseEvent e) { showPopupTabMenu(e) }
void showPopupTabMenu(MouseEvent e) {
Expand All @@ -81,6 +81,14 @@ class TabbedPanel extends JPanel implements PreferencesChangeListener {
}
}
}
void mouseEntered(MouseEvent e) {}
void mouseExited(MouseEvent e) {}
void mouseClicked(MouseEvent e) {
int index = tabPanel.indexAtLocation(e.x, e.y)
if (index != -1 && SwingUtilities.isMiddleMouseButton(e)) {
removeComponent(tabPanel.getComponentAt(index))
}
}
})
return tabPanel
}
Expand Down

0 comments on commit fcee004

Please sign in to comment.