Article View: borland.public.jbuilder.java.swing
Article #695Focus traversal issue
From: Maxim Golubitsky
Date: Sun, 23 Jan 2005 15:13
Date: Sun, 23 Jan 2005 15:13
42 lines
2116 bytes
2116 bytes
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
Technical Details
Message-ID:
<41f3bf14$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-in.ntli.net!newsrout1-win.ntli.net!ntli.net!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 111d45,3e4de782ca912782,start X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Maxim Golubitsky" <spam@golubitsky.com> Newsgroups: borland.public.jbuilder.java.swing Subject: Focus traversal issue Date: Sun, 23 Jan 2005 17:13:23 +0200 Lines: 44 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 212.29.213.11 Message-ID: <41f3bf14$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1106493204 212.29.213.11 (23 Jan 2005 07:13:24 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-in.ntli.net!newsrout1-win.ntli.net!ntli.net!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail