Solved

Tab order control...

Posted on 1998-05-26
4
208 Views
Last Modified: 2010-04-16
I have a panel which contains textfields and choice list components.  The default tab order is whatever order that the components are added, but I want to change that.  What is the best way to override the default tab ordering and create your own tab ordering?
0
Comment
Question by:stepma
4 Comments
 
LVL 2

Expert Comment

by:aziz061097
ID: 1221486
The order of add statements defines the Tab order. Just change the order of the add statements . If you want the display in a particular format use some layout manager to place the componenents as you want but the add statements must be in the order of your tab sequence
0
 
LVL 1

Expert Comment

by:froderik
ID: 1221487
Another way to do it that I haven't tried but just came to think about is to catch KeyEvents for the Panel and use setFocus() method calls to control the order it the key pressed is tab.
0
 
LVL 1

Accepted Solution

by:
dufort earned 50 total points
ID: 1221488
Basically, there are two ways of managing focus on your forms.

FIRST: write a FocusListener class, which will respond to the FocusEvent event with the methods focusGained() and focusLost(). See the Java tutorial for more details at:
http://java.sun.com/docs/books/tutorial/ui/components/focuslistener.html
(NOTE: I don't know if you have to register to the Java Developers Connection to access this page. Anyway, registering is free.)

SECOND: if your are using JFC components, look at the meyhods setNextFocusableComponent() and so on, in com.sun.java.swing.JComponent. For standard AWT components, use the requestFocus() method on the next component to set focus. How to know when to set focus? Implement interface FocusListener on your form.

Hope it helped!

0
 
LVL 4

Expert Comment

by:evijay
ID: 1221489
You can seperate focus traversal into a focusmanager class to which you will give a list of components. To change focus traversal order, pass the same list again in a different order. The focusmanager implements focus listener interface and traverses the focus using requestFocus if the registered listeners on focus traversal agree for that.

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now