Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate Through Tab Components in JTabbedPane

I need to determine which tabs in a JTabbedPane need updated by determining the contents of each tab's component. From what I can determine, there is no way to iterate through each tab using the default JTabbedPane model.

Does anyone have any ideas as to what I could do in this situation?

like image 310
Cole Avatar asked Jul 06 '11 17:07

Cole


People also ask

How do you switch tabs in JTabbedPane by clicking a button?

You should use the method JTabbedPane. setSelectedIndex(int index) with the index of the tab you want. Save this answer.

Which method is used to add tabs to a JTabbedPane?

To Create Tabbed Panes. To create a tabbed pane, instantiate JTabbedPane , create the components you wish it to display, and then add the components to the tabbed pane using the addTab method.

How do I add components to JTabbedPane?

In Swing, JTabbedPane is simply a specialized container. Each tab has a name. To add a tab to the JTabbedPane , simply call addTab() . You'll need to specify the name of the tab as well as a component that supplies the tab's contents.


2 Answers

if you use something like:

int totalTabs = tabbedPane.getTabCount();
for(int i = 0; i < totalTabs; i++)
{
   Component c = tabbedPane.getTabComponentAt(i);
   //other stuff
}

Could give you a start point to do what you want.

like image 187
james_bond Avatar answered Sep 29 '22 13:09

james_bond


How about getTabCount() and getTabComponentAt( int index )?

like image 22
Andy Thomas Avatar answered Sep 29 '22 12:09

Andy Thomas