Java Swing - How to detect doubleclick on tab header in JTabbedPane

562 views Asked by At

Is there any way I can detect doubleclick on tab header in JTabbedPane ?

I do not mean ChangeEvent..

2

There are 2 answers

0
camickr On BEST ANSWER

Add a MouseListener to the tabbed pane.

Then you can determine which tab was double clicked by using something like:

TappedPaneUI ui = tabbedPane.getUI();
int tab = ui.tabForCordinate(...);

if (tab = ??? and doubleClick)
    // do something
1
Ľubomír On

I have found solution few seconds after posting this:

jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
             if (evt.getClickCount()==2 && jTabbedPane1.indexAtLocation(evt.getX(), evt.getY())==3) {
                 //deteced doubleclick on tab with index 3
             }
        }
    });