Explv Posted January 4, 2016 Posted January 4, 2016 (edited) Edit: Nevermind, got the error now: Caused by: java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = pool-1-thread-2 I am having issues with launching a JavaFX application from the onStart method in Script. There is no issue with the application itself, as it works perfectly fine when called from the main method in the same class. I am launching the application using the following code, it produces "error in script onStart()", but no useful message: @Override public void onStart(){ ClassName.launch(ClassName.class); } Thanks Edited January 4, 2016 by Explv 1
Valkyr Posted January 4, 2016 Posted January 4, 2016 (edited) You need to encapsulate it within a JFrame. public class YourGui extends JFXPanel { ... public static JFrame create() { JFrame frame = new JFrame(); YourGui gui = new YourGui (); Platform.runLater(() -> { gui.init(); frame.setContentPane(gui); }); } public void init() { final BorderPane container = new BorderPane(); container.setTop(someComponent); container.setCenter(someOtherComponent); final Scene scene = new Scene(container); setScene(scene); } ... } Edit: You might only need to wrap the GuiClass.launch in a Platform.runLater Edited January 4, 2016 by Valkyr
Explv Posted January 4, 2016 Author Posted January 4, 2016 Edit: You might only need to wrap the GuiClass.launch in a Platform.runLater Just tried: Platform.runLater(() -> ClassName.launch(ClassName.class)); But no dice, I will try your full solution now, thanks man
Mysteryy Posted January 4, 2016 Posted January 4, 2016 You need to encapsulate it within a JFrame. public class YourGui extends JFXPanel { ... public static JFrame create() { JFrame frame = new JFrame(); YourGui gui = new YourGui (); Platform.runLater(() -> { gui.init(); frame.setContentPane(gui); }); } public void init() { final BorderPane container = new BorderPane(); container.setTop(someComponent); container.setCenter(someOtherComponent); final Scene scene = new Scene(container); setScene(scene); } ... } Edit: You might only need to wrap the GuiClass.launch in a Platform.runLater Lool Valk he doesnt know the head ache hes getting himself into.
Valkyr Posted January 4, 2016 Posted January 4, 2016 Lool Valk he doesnt know the head ache hes getting himself into. ikr
Explv Posted January 4, 2016 Author Posted January 4, 2016 You need to encapsulate it within a JFrame. Got it to work by doing this. Thanks dude 1
Valkyr Posted January 4, 2016 Posted January 4, 2016 Got it to work by doing this. Thanks dude No prob, now have fun w/ styling 1