0% found this document useful (0 votes)
27 views2 pages

Code Sample

This method switches the active tab in a tabbed pane (JTabbedPane) based on an action (int) parameter. It gets the current tab index, switches to the previous/next tab if possible while skipping disabled tabs, or resets to the first tab. It then syncs the navigation buttons and processes orders.

Uploaded by

Tom Rochester
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

Code Sample

This method switches the active tab in a tabbed pane (JTabbedPane) based on an action (int) parameter. It gets the current tab index, switches to the previous/next tab if possible while skipping disabled tabs, or resets to the first tab. It then syncs the navigation buttons and processes orders.

Uploaded by

Tom Rochester
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

/* * Method: switchTabs * params:tabs - tabset we are operating on (JTabbedPane) * action - action to be performed (int) * * Provides a method to switch the

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 }

You might also like