-
Enhancement
-
Resolution: Fixed
-
P4
-
1.3.1, 1.4.0
-
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
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
- duplicates
-
JDK-4694015 1.4 REGRESSION: default button does not work reliably for javax.swing.JButton
-
- Closed
-
- relates to
-
JDK-4193995 JTextField keeps focus, precluding Default Btn from rcvg ActionEvts
-
- Closed
-