Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Num pad Enter key returns UNDEFINED(Depending on execution stack, the Enter key from the numeric pad is not correctly transmetted)
Num pad Enter key returns UNDEFINED [message #1794793] Thu, 06 September 2018 14:52 Go to next message
Patrick Muscat is currently offline Patrick MuscatFriend
Messages: 4
Registered: May 2018
Junior Member
Hello,

I'm not sure this is the right place for this problem...

Using JavaFX inside SWT, the keycode of the enter key from the numpad is UNDEFINED.

Here is a very simple example:
package enterkey;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import javafx.embed.swt.FXCanvas;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;

public class TestJavaFXInsideSWT {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());

		final FXCanvas fxCanvas = new FXCanvas(shell, SWT.FILL);
		TextField textField = new TextField("Texte");
		textField.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<Event>() {
			@Override
			public void handle(Event event) {
				if (event instanceof KeyEvent)
					System.out.println(((KeyEvent) event).getCode());
			}
		});
		Group group = new Group(textField);
		Scene scene = new Scene(group, 160, 80);
		fxCanvas.setScene(scene);

		shell.layout();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
}


With pure Javafx everything is fine

package enterkey;

import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;

public class TestJavaFX extends Application {

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) {
		primaryStage.setTitle("Test EnterKey");

		TextField textField = new TextField("Texte");
		textField.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<Event>() {
			@Override
			public void handle(Event event) {
				if (event instanceof KeyEvent)
				System.out.println(((KeyEvent) event).getCode());
			}
		});
		
		Group group = new Group(textField);

		Scene scene = new Scene(group, 160, 80);
		primaryStage.setScene(scene);
		primaryStage.show();
	}
}


With pure SWT, the keycode is different

package enterkey;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class TestSWT {
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());

		Text text = new Text(shell, SWT.NONE);
		text.setText("Texte");
		text.addKeyListener(new KeyListener() {
			@Override
			public void keyReleased(KeyEvent e) {
				// ignorer
			}
			@Override
			public void keyPressed(KeyEvent e) {
				System.out.println(e.keyCode);
			}
		});

		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
}


Any idea or somewhere else to ask?

[Edit] versions:
- jfxswt from jre1.8.0_181
- org.eclipe.swt 3.106.2 (v20171129-0543)
- org.eclipse.swt.win32.win32.x86_64 3.106.2 (.v20171129-0543)

[Updated on: Thu, 06 September 2018 14:59]

Report message to a moderator

Re: Num pad Enter key returns UNDEFINED [message #1794889 is a reply to message #1794793] Mon, 10 September 2018 12:45 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6410
Registered: July 2009
Senior Member
I guess this is a problem if FXCanvas. as this one forwards the SWT events to FX IIRC
Re: Num pad Enter key returns UNDEFINED [message #1794960 is a reply to message #1794889] Tue, 11 September 2018 16:49 Go to previous message
Patrick Muscat is currently offline Patrick MuscatFriend
Messages: 4
Registered: May 2018
Junior Member
Thank you for this response. Is there a quick fix available some where or will I have to override some FXCanvas (sendKeyEventToFX?) method?
Previous Topic:javafx-swt.jar not in the classpath when using java10
Next Topic:Support for Java11 / Open JFX 11 is on the way
Goto Forum:
  


Current Time: Wed Sep 19 01:32:48 GMT 2018

Powered by FUDForum. Page generated in 0.01516 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top