Board index » jbuilder » Focus traversal issue

Focus traversal issue


2005-01-23 11:13:23 PM
jbuilder21
Hello,
I translated my application from AWT to Swing and now have problem with
focus traversal in it.
The problem can be described using following example, where we have three
JTextFields:
One at the left side of two others, that are placed in a JPanel one above
the other.
[ b ]
[ a ]
[ c ]
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame {
public Test(){
getContentPane().setFocusTraversalPolicy(new
ContainerOrderFocusTraversalPolicy());
getContentPane().setLayout(new FlowLayout());
getContentPane().add(new JTextField("a"));
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(2, 1));
panel.add(new JTextField("b"));
panel.add(new JTextField("c"));
getContentPane().add(panel);
pack();
}
public static void main(String[] args){
new Test().show();
}
}
In AWT, the focus was transferred in this order: a - b - c
However, in Swing it goes: b - c - a even if I am trying to explicitly set
ContainerOrderFocusTraversalPolicy.
Can somebody give me an idea how to get it to work in the correct order?
Thank you in advance,
Maxim Golubitsky
 
 

Re:Focus traversal issue

On 1/23/2005 at 10:13:23 AM, Maxim Golubitsky wrote:
Quote
In AWT, the focus was transferred in this order: a - b - c
However, in Swing it goes: b - c - a even if I am trying to explicitly
set ContainerOrderFocusTraversalPolicy.

Can somebody give me an idea how to get it to work in the correct order?
java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
www.JPMcGrath.net/newsgroups/e-mail.html