How do I TAB between containers when using a custom FocusTraversalPolicy in Java 1.4?
Posted on 2006-06-22
My company is upgrading a application from Java 1.3.? to 1.4.2_11. This issue deals not with the upgrade, but a problem using the TAB key. End-users have a requirement on certain "screens" to use the Tab key and go through the data-entry components in a special order. This worked in 1.3 using NextFocusableComponent() in the bottom-most container, usually a JPanel. My example below will cover ONE InternalFrame, but the application has over 120 containers that will need to be fixed.
I can use the FocusTraversalPolicy to Tab through the components in ONE container, but I cannot get to/from other containers. I will try to give a brief overview of part of the application.
The example part of the Windows application starts with a new JInternalFrame from the main menu.
The JInternalFrame contains focusable components: text-fields, check-boxes, buttons, a TabbedPage, and a JPanel for the button bar at the bottom (everything is on GridBagLayouts).
The tabbedPage has 4 tabs, each with a JPanel full of focusable components. We can call them tabPanel1, tabPanel2, tabPanel3, tabPanel4.
tabPanel1 has 28 focusable components that need to be in a special order. I can do that in an endless loop with the myFocusTraversalPolicy() on the panel.
I can TAB from each component (0,1,2,...26,27,0,1,2,3,...) just fine, but I need 3 things to happen differently:
1. If I SHIFT+TAB from the first component on the tabPanel1 (a text field), I want the focus to be on the tab of the tabbed page.
2. If I TAB from the last component, I want the focus to be on button1 of the buttonPanel (below the tabbed page), then TAB through the buttons.
3. If I TAB on the last button, I want the focus to be on the first component (another text field) of the JInternalFrame (top of the screen).
I would provide a code example, but it is a multi-tiered application with a ridiculous amount of code and classes. All documentation I have found works great for controlling focusable components within a container, but not moving from container to container. Just hard-coding the focus to the desired container didn't work. Please help!