-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.0
-
None
-
sparc
-
solaris_8
Solaris and Windows differ in the KeyEvents that are dispatched when a key is held down. On Windows, a continuous stream of KEY_PRESSED and KEY_TYPED events are sent for as long as a key is held down. On Solaris, KEY_PRESSED, KEY_TYPED, and KEY_RELEASED events are sent for as long as the key is held down. One nasty side effect of this is that if you hold down the space bar while a JButton has the input focus, a continuous stream of ActionEvents will be fired as well. This is demonstrable using the OptionPane demo in SwingSet2, as well as the following test case. This behavior goes back at least to 1.2.2.
KeyTest.java:
// check for repeated key messages on Solaris but not Windows
import javax.swing.*;
import java.awt.event.*;
public class KeyTest extends JFrame implements KeyListener, ActionListener {
JButton button;
public KeyTest() {
super("KeyTest");
button = new JButton("A JButton");
button.addActionListener(this);
button.addKeyListener(this);
getContentPane().add(button);
setSize(200, 200);
}
public static void main(String[] args) {
KeyTest kt = new KeyTest();
kt.show();
}
public void actionPerformed(ActionEvent e) {
System.out.println("actionPerformed()");
}
public void keyPressed(KeyEvent e) {
System.out.println("keyPressed()");
}
public void keyReleased(KeyEvent e) {
System.out.println("keyReleased()");
}
public void keyTyped(KeyEvent e) {
System.out.println("keyTyped()");
}
}
KeyTest.java:
// check for repeated key messages on Solaris but not Windows
import javax.swing.*;
import java.awt.event.*;
public class KeyTest extends JFrame implements KeyListener, ActionListener {
JButton button;
public KeyTest() {
super("KeyTest");
button = new JButton("A JButton");
button.addActionListener(this);
button.addKeyListener(this);
getContentPane().add(button);
setSize(200, 200);
}
public static void main(String[] args) {
KeyTest kt = new KeyTest();
kt.show();
}
public void actionPerformed(ActionEvent e) {
System.out.println("actionPerformed()");
}
public void keyPressed(KeyEvent e) {
System.out.println("keyPressed()");
}
public void keyReleased(KeyEvent e) {
System.out.println("keyReleased()");
}
public void keyTyped(KeyEvent e) {
System.out.println("keyTyped()");
}
}
- duplicates
-
JDK-4504217 Standardize autorepeat KeyEvent behavior across platforms
- Open