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

REGRESSION: In JTextArea setEditable(...) breaks focus traversal keys

XMLWordPrintable

    • b28
    • x86
    • windows_2000



      Name: rmT116609 Date: 03/27/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
      Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      If you have a JTextArea where you have explicitly set the focus traversal keys to be used using the setFocusTraversalKeys(...) method and you make a subsequent call to setEditable(false) and then setEditable(true), the focus traversal keys that have been set no longer function.

      This is a big issue for screens where fields start off non-editable until you enter an id or something at which time the fields are set editable (which we do all over our application).

      I tested this in using JDK1.4.1_02, JDK1.4.1_01, and JDK1.4.0. It appears to be broken in both of the 1.4.1 release but works fine in the 1.4.0 release.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1). Run the example code provided.
      2). Using the <tab> key you should be able to traverse from the JTextField to the JTextArea to the next JTextField and so on.
      3). Press the 'Break Focus' button.
      4). Now if you put focus into the top JTextField and press <tab> to navigate into the JTextArea, subsequent <tab> presses will add tabs to the JTextArea instead of transfering focus to the next JTextField

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Regardles of when setEditable(boolean) is called on a JTextArea, any focus traversal keys that have been explicitly set should always function.
      Calling setEditable(boolean) on the JTextArea seems to cancel out any previously set focus traversal keys making the JTextArea not function how it was designated to function.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import java.util.*;

      public class Example extends JFrame implements ActionListener
      {
          public static void main(String [] args)
          {
              Example e = new Example();
              e.pack();
              e.setVisible(true);
          }

          public Example()
          {
              super("Example");
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              ta = new JTextArea(5,20);
              HashSet keys = new HashSet(1);
              keys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0, false));
              ta.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys);
              keys = new HashSet(1);
              keys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK, false));
              ta.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys);

              JPanel p = new JPanel(new BorderLayout());
              p.add(new JTextField(), "North");
              p.add(new JScrollPane(ta), "Center");
              p.add(new JTextField(), "South");
              getContentPane().add(p, "Center");

              p = new JPanel();
              JButton b = new JButton("Break Focus");
              b.addActionListener(this);
              p.add(b);
              getContentPane().add(p, "South");
          }

          public void actionPerformed(ActionEvent e)
          {
              ta.setEditable(false);
              ta.setEditable(true);
          }

          private JTextArea ta;
      }
      ---------- END SOURCE ----------

      Release Regression From : 1.4.0_03
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Review ID: 183103)
      ======================================================================

            idk Igor Kushnirskiy (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: