Jump to content

Launching a JavaFX Application from Script


Recommended Posts

Posted (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 by Explv
  • Like 1
Posted (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 by Valkyr
Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...