Mac OSX and German Keyboard Layout (Y/Z)

Kevin Rushforth kevin.rushforth at oracle.com
Fri Feb 26 01:39:10 UTC 2016


Hi Tom,

Please file a bug so we can look at it.

Thanks.

-- Kevin


Tom Schindl wrote:
> Hi,
>
> Anyone any insights? Any Swing Savy dev around who knows how Swing
> manages to deliver the right key?
>
> Tom
>
> On 22.01.16 13:30, Tom Schindl wrote:
>   
>> Hi,
>>
>> I just discovered that the KeyCode reported by JavaFX on OS-X with a
>> german keyboard layout (where eg z and y are interchanged) is wrong.
>>
>> If you press a Z you get as the KeyCode.Y and for Y you get KeyCode.Z -
>> this Y/Z problem. I don't think that I as a java-dev need to deal with
>> that and if you look at other toolkits (swing, swt) they handle this
>> transparently for me!
>>
>> I've attached you a javafx and swing application and you'll notice that
>> swing reports always the correct keycode (no matter if my keyboard
>> layout is english or german) and javafx is wrong on german keyboards.
>>
>>
>> FX:
>>     
>>> package application;
>>>
>>> import javafx.application.Application;
>>> import javafx.scene.Scene;
>>> import javafx.scene.control.TextField;
>>> import javafx.scene.layout.BorderPane;
>>> import javafx.stage.Stage;
>>>
>>>
>>> public class Main extends Application {
>>> 	@Override
>>> 	public void start(Stage primaryStage) {
>>> 		try {
>>> 			BorderPane root = new BorderPane();
>>>
>>> 			TextField f = new TextField();
>>> 			f.setOnKeyPressed( e -> {
>>> 				System.err.println("KeyCode: " + e.getCode());
>>> 			});
>>>
>>> 			root.setCenter(f);
>>>
>>> 			Scene scene = new Scene(root,400,400);
>>> 			primaryStage.setScene(scene);
>>> 			primaryStage.show();
>>> 		} catch(Exception e) {
>>> 			e.printStackTrace();
>>> 		}
>>> 	}
>>>
>>> 	public static void main(String[] args) {
>>> 		launch(args);
>>> 	}
>>> }
>>>       
>> Swing:
>>     
>>> package application;
>>>
>>> import java.awt.event.KeyEvent;
>>> import java.awt.event.KeyListener;
>>>
>>> import javax.swing.JFrame;
>>> import javax.swing.JTextField;
>>>
>>> public class SampleSwing extends JFrame {
>>> 	public SampleSwing() {
>>> 		JTextField textField = new JTextField();
>>> 		textField.addKeyListener(new KeyListener() {
>>>
>>> 			@Override
>>> 			public void keyTyped(KeyEvent e) {
>>> 				// TODO Auto-generated method stub
>>>
>>> 			}
>>>
>>> 			@Override
>>> 			public void keyReleased(KeyEvent e) {
>>> 				// TODO Auto-generated method stub
>>>
>>> 			}
>>>
>>> 			@Override
>>> 			public void keyPressed(KeyEvent e) {
>>> 				System.err.println((char)e.getKeyCode());
>>> 			}
>>> 		});
>>> 		getContentPane().add(textField);
>>> 	}
>>>
>>> 	public static void main(String[] args) {
>>> 		new SampleSwing().setVisible(true);
>>>
>>> 	}
>>> }
>>>       
>>
>> Tom
>>
>>     
>
>
>   


More information about the openjfx-dev mailing list