-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.2.0
-
x86
-
windows_nt
When we inputted space key or enter(return) key in JTextField, the differences of action of KeyEvent happened between on Solaris and Windows NT.
We found the differences of action of KeyEvent in following four cases.
- case1 : when we input <space> in JTextField without mode of inputting
japanese
- case2 : when we input <space> in JTextField with mode of inputting japanese
(as no translation)
- case3 : when we input <space> in JTextField with mode of inputting japanese
(as translation)
- case4 : when we input <enter> (Return key) in JTextField with mode of
inputting japanese (as translation)
The detail of result is below (o : KeyEvent appears , x : KeyEvent didn't appear ),
- case1 :
Solaris Wnn6 ATOK8 cs00 WinNT(MS-IME97,ATOK11)
keyPressed o o o o
keyTyped o o o x
keyReleased o o o o
- case2 :
Solaris Wnn6 ATOK8 cs00 WinNT(MS-IME97,ATOK11)
keyPressed o x x x
keyTyped o x x x
keyReleased o x x o
- case3 :
Solaris Wnn6 ATOK8 cs00 WinNT(MS-IME97,ATOK11)
keyPressed x x x x
keyTyped x x x x
keyReleased x x x o
- case4 :
Solaris Wnn6 ATOK8 cs00 WinNT(MS-IME97,ATOK11)
keyPressed x x o x
keyTyped x x o x
keyReleased x x o o
These results may be dependent of each IME, but we think that java must be
independent of platform. So, especially, we hope next points.
1. In case1, keyTyped event happens on windows NT.
2. In case2, case3 and case4 , keyReleased event don't happen on Windows NT.
Then these results can be reproduced by following IMFTest.java .
---------------------------- IMFTest.java ------------------------------------
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class IMFTest extends JPanel implements KeyListener {
private JTextField inputField;
private String emptyString = "";
public IMFTest() {
inputField = new JTextField(10);
add(inputField);
inputField.addKeyListener(this);
}
public void keyTyped(KeyEvent e) {
System.out.println("KeyTyped event is pressed.");
Object o = e.getSource();
if (o instanceof JTextComponent) {
JTextComponent tc = (JTextComponent)o;
String input = tc.getText();
if (input.length() == 0 || input.charAt(0) != '"') {
char c = e.getKeyChar();
if (Character.isLetter(c) && Character.isLowerCase(c)) {
e.setKeyChar(Character.toUpperCase(c));
}
}
}
}
public void keyPressed(java.awt.event.KeyEvent e) {
System.out.println("KeyPressed event is pressed.");
}
public void keyReleased(KeyEvent e){
System.out.println("KeyReleased event is pressed.");
Object o = e.getSource();
if (o instanceof JTextComponent) {
JTextComponent tc = (JTextComponent)o;
switch (e.getKeyCode()) {
case KeyEvent.VK_ENTER:
case KeyEvent.VK_SPACE:
{
String input = tc.getText();
if (input.equals(emptyString) || input.equals("")) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
} else {
}
} else {
String s = null;
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
s = input;
} else {
s = input.substring(0,input.length() - 1);
}
}
tc.setText(emptyString);
}
break;
}
}
}
public static void main(String args[]) {
JFrame frame = new JFrame("IMF Test");
IMFTest IMFpanel = new IMFTest();
frame.getContentPane().add(IMFpanel);
frame.pack();
frame.setSize(200,200);
frame.setVisible( true );
}
}
-------------------------------------------------------------------------------------
We found the differences of action of KeyEvent in following four cases.
- case1 : when we input <space> in JTextField without mode of inputting
japanese
- case2 : when we input <space> in JTextField with mode of inputting japanese
(as no translation)
- case3 : when we input <space> in JTextField with mode of inputting japanese
(as translation)
- case4 : when we input <enter> (Return key) in JTextField with mode of
inputting japanese (as translation)
The detail of result is below (o : KeyEvent appears , x : KeyEvent didn't appear ),
- case1 :
Solaris Wnn6 ATOK8 cs00 WinNT(MS-IME97,ATOK11)
keyPressed o o o o
keyTyped o o o x
keyReleased o o o o
- case2 :
Solaris Wnn6 ATOK8 cs00 WinNT(MS-IME97,ATOK11)
keyPressed o x x x
keyTyped o x x x
keyReleased o x x o
- case3 :
Solaris Wnn6 ATOK8 cs00 WinNT(MS-IME97,ATOK11)
keyPressed x x x x
keyTyped x x x x
keyReleased x x x o
- case4 :
Solaris Wnn6 ATOK8 cs00 WinNT(MS-IME97,ATOK11)
keyPressed x x o x
keyTyped x x o x
keyReleased x x o o
These results may be dependent of each IME, but we think that java must be
independent of platform. So, especially, we hope next points.
1. In case1, keyTyped event happens on windows NT.
2. In case2, case3 and case4 , keyReleased event don't happen on Windows NT.
Then these results can be reproduced by following IMFTest.java .
---------------------------- IMFTest.java ------------------------------------
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class IMFTest extends JPanel implements KeyListener {
private JTextField inputField;
private String emptyString = "";
public IMFTest() {
inputField = new JTextField(10);
add(inputField);
inputField.addKeyListener(this);
}
public void keyTyped(KeyEvent e) {
System.out.println("KeyTyped event is pressed.");
Object o = e.getSource();
if (o instanceof JTextComponent) {
JTextComponent tc = (JTextComponent)o;
String input = tc.getText();
if (input.length() == 0 || input.charAt(0) != '"') {
char c = e.getKeyChar();
if (Character.isLetter(c) && Character.isLowerCase(c)) {
e.setKeyChar(Character.toUpperCase(c));
}
}
}
}
public void keyPressed(java.awt.event.KeyEvent e) {
System.out.println("KeyPressed event is pressed.");
}
public void keyReleased(KeyEvent e){
System.out.println("KeyReleased event is pressed.");
Object o = e.getSource();
if (o instanceof JTextComponent) {
JTextComponent tc = (JTextComponent)o;
switch (e.getKeyCode()) {
case KeyEvent.VK_ENTER:
case KeyEvent.VK_SPACE:
{
String input = tc.getText();
if (input.equals(emptyString) || input.equals("")) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
} else {
}
} else {
String s = null;
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
s = input;
} else {
s = input.substring(0,input.length() - 1);
}
}
tc.setText(emptyString);
}
break;
}
}
}
public static void main(String args[]) {
JFrame frame = new JFrame("IMF Test");
IMFTest IMFpanel = new IMFTest();
frame.getContentPane().add(IMFpanel);
frame.pack();
frame.setSize(200,200);
frame.setVisible( true );
}
}
-------------------------------------------------------------------------------------
- duplicates
-
JDK-4186905 JTextPane no longer dispatches keyTyped events to a KeyListener
- Resolved