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

Non-editable JTextArea and similar should allow Tab to keyboard - accessibility

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.1
    • 1.3.1
    • client-libs
    • hopper
    • generic
    • generic
    • Verified

      JTextArea, JTextPane, etc. swallow the Tab key. This makes sense when editing
      is allowed, but when the component is uneditable, it causes unneeded frustration and damages keyboard accessibility.

      Forcing the user to type Control+Tab is needlessly complex.

      This is a very easy fix:

      myTextComponent = new javax.swing.JTextPane {
        //override this so tab is not swallowed by this component
        public boolean isManagingFocus() {
          return false;
        }
      };

      =========
      Test case

      -- TextTest.java
      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);
          }
      }
      --

      Steps to reproduce.
      1. run TextTest
      2. select textArea by mouse
      4. press tab
      5. focus should move to next component

      ###@###.### 2002-04-19

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: