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 (nes开发者_C百科ted class).
Can anybody please suggest how?
Your component has a parent, eventually the JTabbedPane
. JTabbedPane
has methods like getSelectedIndex()
or getSelectedComponent()
.
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 ....
}
}
精彩评论