How to check if tab is active or not in JTabbedPane?

How to check if a tab is active in a JTabbedPane instance or not in a tab class (nested class), and not in a wrapper class?

I know that there is a booloean isEnabledAt(int index); method booloean isEnabledAt(int index); , but this method can only be called in the enclosing class. While I want to check if a tab is selected in the current tab class (nested class).

Can anyone suggest how?

+7
java swing jtabbedpane
source share
2 answers

In your parent component, eventually JTabbedPane . JTabbedPane has methods like getSelectedIndex() or getSelectedComponent() .

+13
source share

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

To determine which tab was selected, use the ChangeEvent . This is a very easy way to perform an action each time you select a tab. Hope this helps someone else, although 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 .... } } 
+7
source share

All Articles