Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Invalid Thread Access(Trying to open a FXDialog through an RCP Event Handler)
Invalid Thread Access [message #1766607] Fri, 23 June 2017 12:29 Go to next message
Alexander Kerner is currently offline Alexander KernerFriend
Messages: 18
Registered: January 2015
Junior Member
I have the following event handler:

public class AssignPAMHandler {
	private static final Logger logger = Logger.getLogger(AssignPAMHandler.class);
	@Execute
	public void execute() {
		System.err.println(Thread.currentThread());
		showDialog();
	}
	private void showDialog() {
		Display.getDefault().asyncExec(() -> showDialogSWT());
	}
	private void showDialogSWT() {
		System.err.println(Thread.currentThread());
		new JFXPanel(); // initializes JavaFX environment
		Platform.runLater(() -> showDialogFX());
	}
	private void showDialogFX() {
		System.err.println(Thread.currentThread());
		TextInputDialog dialog = new TextInputDialog("walter");
		dialog.setTitle("Text Input Dialog");
		dialog.setHeaderText("Look, a Text Input Dialog");
		dialog.setContentText("Please enter your name:");
		dialog.showAndWait().ifPresent(name -> System.out.println("Your name: " + name));
	}
}


When I execute this handler via a menu item, I get the following output and exception (the dialog shows up, nevertheless):

Thread[main,6,main]
Thread[main,6,main]
Thread[JavaFX Application Thread,6,main]
Exception in thread "JavaFX Application Thread" org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(SWT.java:4533)
	at org.eclipse.swt.SWT.error(SWT.java:4448)
	at org.eclipse.swt.SWT.error(SWT.java:4419)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:483)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:421)
	at org.eclipse.swt.widgets.Widget.getData(Widget.java:537)
	at org.eclipse.e4.ui.internal.workbench.swt.ShellActivationListener.handleEvent(ShellActivationListener.java:61)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1605)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1339)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1366)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1345)
	at org.eclipse.swt.widgets.Shell.filterProc(Shell.java:807)
	at org.eclipse.swt.widgets.Display.filterProc(Display.java:1621)
	at com.sun.glass.ui.gtk.GtkApplication.enterNestedEventLoopImpl(Native Method)
	at com.sun.glass.ui.gtk.GtkApplication._enterNestedEventLoop(GtkApplication.java:211)
	at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:511)
	at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
	at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:583)
	at javafx.stage.Stage.showAndWait(Stage.java:474)
	at javafx.scene.control.HeavyweightDialog.showAndWait(HeavyweightDialog.java:162)
	at javafx.scene.control.Dialog.showAndWait(Dialog.java:341)
	at net.openchrom.chromatogram.xxd.identifier.supplier.chromident.ui.handler.AssignPAMHandler.showDialogFX(AssignPAMHandler.java:54)


The executing thread seems to be the same all the time and the FX dialog shows up. Nevertheless, the exception is thrown.
Re: Invalid Thread Access [message #1766646 is a reply to message #1766607] Fri, 23 June 2017 19:28 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6365
Registered: July 2009
Senior Member
Why JFXPanel? Use FXCanvas to bootstrap JavaFX in an SWT env
Re: Invalid Thread Access [message #1766647 is a reply to message #1766646] Fri, 23 June 2017 19:29 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6365
Registered: July 2009
Senior Member
Oh and no need for Platform.runLater JavaFX and SWT run on the same Event thread
Re: Invalid Thread Access [message #1766648 is a reply to message #1766647] Fri, 23 June 2017 20:08 Go to previous message
Alexander Kerner is currently offline Alexander KernerFriend
Messages: 18
Registered: January 2015
Junior Member
Oh Mann, Thanks Thomas, tiny stupid copy/paste mistake big confusions ;) Just replace JFXPanel -> FXCanvas to make it run as expected ;)
Previous Topic:RCP restart
Next Topic:Proper way of consuming third party javafx components in Efxclipse RCP
Goto Forum:
  


Current Time: Sat Dec 16 16:52:55 GMT 2017

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

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