Code Sample
Code Sample
active interface tab. Works across * all modes of the application. Calls setNavButtons (JTabbedPane tabs) * to sync buttons states. */ public void switchTabs(JTabbedPane tabs, int action) { int currentTab = tabs.getSelectedIndex(); // Get active tab switch (action) { case BACK: // Back button was clicked, move to the previous tab if (currentTab > 0) { // are we on the first tab? currentTab -= 1; while (!tabs.isEnabledAt(currentTab) && currentTab > 0) { currentTab -= 1; // bypass disabled tabs } if (currentTab < 0) { //did we go too far? currentTab = 0; } tabs.setSelectedIndex(currentTab); // set the new active tab } setNavButtons(tabs); // sync button state break; case NEXT: // Next button was clicked, move to the next tab if (currentTab < tabs.getTabCount() - 1) { // are we on the last tab? currentTab += 1; while (!tabs.isEnabledAt(currentTab) && currentTab <= tabs.getTabCount() - 1) { currentTab += 1; // bypass disabled tabs } if (currentTab > tabs.getTabCount() - 1) { // did we go too far? currentTab = tabs.getTabCount() - 1; } tabs.setSelectedIndex(currentTab); // set the new active tab } setNavButtons(tabs); // sync button state break; case RESET: // Reset button was clicked, reset the interface and objects tabs.setSelectedIndex(0); //set active tab to the first tab resetForm(); // reset the entire interface and all objects setNavButtons(tabs); // sync button state break;
default: // fallthrough event should never be hit setNavButtons(tabs); // sync button state break; } processOrder(); // work, work, work }