Hi Wim,

    The same also happens with the second JTextArea if you press
Shift-Tab from the button.  And for the same reasons.  Change these
two lines in the MyTextArea constructor from "true" to "false":


forwardFocusTraversalKeys.add(
   AWTKeyStroke.getAWTKeyStroke(
      KeyEvent.VK_TAB, 0, true ) );
...
backwardFocusTraversalKeys.add(
   AWTKeyStroke.getAWTKeyStroke(
      KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK, true ) );

    to


forwardFocusTraversalKeys.add(
   AWTKeyStroke.getAWTKeyStroke(
      KeyEvent.VK_TAB, 0, false ) );
...
backwardFocusTraversalKeys.add(
   AWTKeyStroke.getAWTKeyStroke(
      KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK, false ) );


    It's also helpful and likely to draw more response if you send
compilable code.  That includes import statements.  Best,


                                                         Joe Sam

Joe Sam Shirah -        http://www.conceptgo.com
conceptGO         -        Consulting/Development/Outsourcing
Java Filter Forum:       http://www.ibm.com/developerworks/java/
Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
Going International?    http://www.jguru.com/faq/I18N
Que Java400?             http://www.jguru.com/faq/Java400



----- Original Message -----
From: "Deblauwe, Wim" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 29, 2003 7:48 AM
Subject: weird focus behaviour with 2 JTextArea's


> Hi,
>
> I want enable TAB/SHIFT-TAB in a JTextArea to go to the next JTextArea and
> not print a tab character in the JTextArea. This can be easily done with
> setFocusTraversalKeys(). But I found something strange. Below is a
> testprogram with one JButton and 2 JTextArea's. When the program is
started,
> focus is on the JButton. Press TAB and the focus will go to the first
> JTextArea and immediately to the second JTextArea. If you place the focus
> with the mouse on the first JTextArea and press tab, it goes to the second
> as it should.
>
> Can someone explain this behaviour?
>
> Below is the code of my testprogram...
>
> public class FocusTest extends JFrame
> {
>  public static void main( String[] args )
>  {
>   FocusTest test = new FocusTest();
>   test.pack();
>   test.setVisible(true);
>  }
>
>  public FocusTest() throws HeadlessException
>  {
>   super("Focus Test");
>   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>
>   setContentPane( createContent() );
>
>  }
>
>  private JPanel createContent()
>  {
>   JPanel panel = new JPanel();
>   panel.setBorder( BorderFactory.createEmptyBorder(12,12,12,12));
>   panel.setLayout( new BoxLayout(panel, BoxLayout.Y_AXIS));
>   JButton button = new JButton("Test button");
>   panel.add(button);
>
>   JTextArea textArea1 = new MyTextArea();
>   panel.add( textArea1 );
>
>   panel.add( Box.createVerticalStrut(7));
>
>   JTextArea textArea2 = new MyTextArea();
>   panel.add( textArea2 );
>
>   return panel;
>  }
>
>  private class MyTextArea extends JTextArea
>  {
>   public MyTextArea()
>   {
>    super(10, 50);
>    Set forwardFocusTraversalKeys = new HashSet();
>
>
forwardFocusTraversalKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
> 0, true));
>    setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
> forwardFocusTraversalKeys);
>
>    Set backwardFocusTraversalKeys = new HashSet();
>
>
backwardFocusTraversalKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
> InputEvent.SHIFT_DOWN_MASK, true));
>    setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
> backwardFocusTraversalKeys);
>   }
>  }
>
> }
>
>
> Ing. Wim Deblauwe







_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to