Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6500709

JTextArea does not not ignore Tab with setFocusTraversalKeysEnabled(true)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 5.0
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :

      The tab key is not ignored in JTextArea although setFocusTraversalKeysEnabled(true) is set.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile coding and press tab several times.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Tab on JTextArea is going to the next component, e..g in this example to the button.
      ACTUAL -
      Tab is excecuted within the JTextArea.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Example:

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JTextArea;

      public class Test extends JFrame {
         Test(){
            JTextArea ta = new JTextArea("Test");
            JButton button = new JButton("Moin");
            ta.setFocusTraversalKeysEnabled(true);
            getContentPane().add(ta, java.awt.BorderLayout.NORTH);
            getContentPane().add(button, java.awt.BorderLayout.CENTER);
            
            
         }
         public static void main (String[] args) {
            Test test = new Test();
            test.pack();
            test.setVisible(true);
         }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      You can catch the key events yourself.

      ta.addKeyListener(new KeyAdapter()
              {
                  public void keyPressed(KeyEvent e)
                  {
                      if (e.getKeyCode() == KeyEvent.VK_TAB)
                      {
                          e.consume();
                          KeyboardFocusManager.
                              getCurrentKeyboardFocusManager().focusNextComponent();
                      }
       
                      if (e.getKeyCode() == KeyEvent.VK_TAB
                      && e.isShiftDown())
                      {
                          e.consume();
                          KeyboardFocusManager.
                              getCurrentKeyboardFocusManager().focusPreviousComponent();
                      }
                  }
              });

            peterz Peter Zhelezniakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: