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

JTextField & non-editable JTextArea bind return key - default btn not accessible

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.1
    • 1.3.1, 1.4.0
    • client-libs
    • hopper
    • generic, x86
    • generic, linux
    • Verified

      JTextField swallows the return key, which makes it difficult for the user to access the default button on a dialog box when the focus is on the JTextField component.

      The Java Look and Feel Design Guidelines do not specify any binding for JTextField for Return/Enter.

      JTextArea has a similar problem. An editable JTextArea needs to bind the return key, but this does not make sense when the JTextArea is non-editable (but focusable).

      There may be other text components with similar problems.

      Components that needlessly swallow the return key negatively affect keyboard accessibility of swing applications.

      -----------------------------------------------------
      Here is a test case for the bug.

      -- TextTest.java

      import java.util.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.text.*;


      public class TextTest {
          static JTextComponent ed;
          public static void main(String[] args) {
              JFrame f = new JFrame("test");
              f.setVisible(true);
              JDialog frame = new JDialog(f,"TextTest");
              JButton button = new JButton("west");
              frame.getContentPane().add(button,BorderLayout.WEST);
              button = new JButton("button");
              frame.getContentPane().add(button,BorderLayout.SOUTH);
              button.addActionListener(
                                       new ActionListener() {
                                           public void actionPerformed(ActionEvent ae) {
                                               System.out.println("button pressed "+ae);
                                               ed.setEditable(!ed.isEditable());
                                           }
                                       });
              frame.getRootPane().setDefaultButton(button);
              JTextComponent editor = new JTextArea("JTextArea");
              ed = editor;
              //editor.setEditable(false);
              //editor.disable();
              frame.getContentPane().add(editor,BorderLayout.NORTH);
              editor = new JTextArea("JTextArea");
              editor.setEditable(false);
              //editor.disable();
              frame.getContentPane().add(editor,BorderLayout.CENTER);
              frame.pack();
              frame.setVisible(true);
          }
      }

      ---
      Select TextField or TextArea by mouse.
      Press enter.
      Button 'button' should be pressed and "button pressed" should be printed to sistem out.

      ###@###.### 2002-04-18

            idk Igor Kushnirskiy (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: