Title: RE: weird focus behaviour with 2 JTextArea's

Thank you for your response and sorry about the import statements. I'm getting too used to using IntelliJ I'm afraid. There all I need to do is press ALT-ENTER, and import are automatically added.

kind regards,

Wim

-----Original Message-----
From: Joe Sam Shirah [mailto:[EMAIL PROTECTED]]
Sent: woensdag 29 oktober 2003 18:39
To: [EMAIL PROTECTED]
Subject: Re: weird focus behaviour with 2 JTextArea's



    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
- - - - - - - - DISCLAIMER - - - - - - - -
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.

Reply via email to