Jump to content

Launching a JavaFX Application from Script


Explv

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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