Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether the tab is active or not in JTabbedPane?

How can I check whether a tab in a JTabbedPane instance is active or not, in the class of the tab (nested class) itself and not in the enclosing class?

I know that there is a method booloean isEnabledAt(int index); but this method can only be called in the enclosing class. Whereas I want to check whether the tab is currently selected within the tab class itself (nested class).

Can anybody please suggest how?

like image 501
Supereme Avatar asked May 30 '10 05:05

Supereme


2 Answers

Your component has a parent, eventually the JTabbedPane. JTabbedPane has methods like getSelectedIndex() or getSelectedComponent().

like image 68
miku Avatar answered Nov 07 '22 15:11

miku


I know that this is old topic, but I found it when looking for a solution to a similar (though slightly different) problem.

To determine what tab was selected, use a ChangeEvent listener. This is a very simple way to perform an action whenever a tab is selected. Hopefully this will help someone else, though this is an old topic.

private void zakladkiStateChanged(javax.swing.event.ChangeEvent evt) 
{                                      
    if (zakladki.getTitleAt(zakladki.getSelectedIndex()).equals("tab title here")) 
    {
        // what you wish to do when tab is selected here ....
    }
} 
like image 7
Bulit Avatar answered Nov 07 '22 17:11

Bulit