I have 3 jTabbedPane in my application which visibility switches based on other selections in the app. what I want to do is have a single set of navigation buttons (back) (next) that will traverse the visible jTabbedPane. I can do it with 3 sets of essentially the same code but am trying to keep this app as small as possible. how can i reference the visible jTabbedPane in my traversal code without writing the same code for each jTabbedPane?
Here is the code that traverses the tabspublic void switchTabs(String action) { Integer tabCount = tabContainer.getTabCount() - 1; Integer currentTab = tabContainer.getSelectedIndex(); if (action.equals("back")) { if (currentTab > 0) { nextButton.setEnabled(true); currentTab -= 1; while (!tabContainer.isEnabledAt(currentTab) && currentTab > 0){ currentTab -= 1; } tabContainer.setSelectedIndex(currentTab); } } else if (action.equals("next")) { if (currentTab < tabCount) { backButton.setEnabled(true); currentTab += 1; while (!tabContainer.isEnabledAt(currentTab) && currentTab < tabCount){ currentTab += 1; } tabContainer.setSelectedIndex(currentTab); } } else if (action.equals("reset")) { tabContainer.setSelectedIndex(0); currentTab = 0; } if (currentTab == tabCount){ nextButton.setEnabled(false); backButton.setEnabled(true); } else if (currentTab == 0){ nextButton.setEnabled(true); backButton.setEnabled(false); } else { nextButton.setEnabled(true); backButton.setEnabled(true); } //calculate(); }
If I could pass the jTabbedPane I want to work with into switchTabs(), it would be perfect but I do not know how to do that and haven't been able to find any information through searching. Any ideas would be helpful. Thank you.