Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I TAB between containers when using a custom FocusTraversalPolicy in Java 1.4?

Posted on 2006-06-22
3
Medium Priority
?
435 Views
Last Modified: 2012-08-13
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!
0
Comment
Question by:FreemanIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
StillUnAware earned 2000 total points
ID: 16961865
For the 2nd and 3rd part You can do this:

2. the last component implements awt.event.FocusListener and overrides the method focusLost, in that method trasfer the focus from the last component to the button1 on the button pannel: button1.requestFocus. Also notice that the button1 must be final or someway else accessible for the last component in the different container.

3. similar to the 2nd part solution.

But I'm not sure how to do the first part, I can only guess that You'll have to use KeyListener and FocusListener simultaniuosly
0
 

Author Comment

by:FreemanIS
ID: 16964610
Thank you!  The TAB key will work throughout the screen on the first tabbed pane, now I have to get the other 4 tabbed panes with panels to work.  I will know more by Friday afternoon.  The SHIFT+TAB works except for one point where I am in the top text field on the panel.  At that point, I want to set the focus on the physical "tab" for the current pane.  It can receive a focus when you press TAB from the button above it, then TAB to the text field.

Forward works:
1. button has focus, then press TAB key
2. tabbed pane header has focus, then press TAB key
3. text field has focus, and so on...

Backwards doesn't work:
1. textField2 has focus, then press SHIFT+TAB
2. textField1 has focus (it worked correctly), then press SHIFT+TAB
3. nothing has focus, it's just gone
4. press SHIFT+TAB again, and the button (above the tabbed pane) has focus. (same button as Forward step 1, above)


0
 

Author Comment

by:FreemanIS
ID: 16971808
Final follow-up:
The TAB key now works.  It is impossible to get the SHIFT+TAB (reverse) to work because of a sub-set of base classes do not have a necessary method.  It is missing JTabbedPane.setSelectedComponent() method.  That is preventing me from setting the focus on the tab header.  Thus, part 3 of my original question is not possible without a change to my company's base class structure.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question