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

Supereme picture Supereme · May 30, 2010 · Viewed 14.6k times · Source

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?

Answer

miku picture miku · May 30, 2010

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