Lolitta
Lolitta

Reputation: 79

How to call javafx class from java class?

I have called from my java class another javafx class as a background thread.

     while(true)
     {
    ....
    .... (build new arguments)
    ....

    Thread t = new Thread() {
        public void run() {
            ChartData.main(arguments);
        }
    };
    t.start();
    }

I get an ERROR:

Exception in thread "Thread-7" java.lang.IllegalStateException: Application launch must not be called more than once at om.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:94) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:75) at javafx.application.Application.launch(Application.java:209)

with javafx class I have constructed only a scatterplot and all my other objects have been achieved in java class.

Thank you for your Help.

Upvotes: 0

Views: 105

Answers (1)

Ingo
Ingo

Reputation: 36339

This is not the way JavaFX works.

You have 2 options:

  1. make your program a proper JavaFX application, and just update the content of your drawing, GUI, or whatever. (You don't need an extra thread for this: just submit something to the UI thread with invokeLater.)

  2. Instead of a thread, run the separate JavaFX in its own process, see ProcessBuilder. Though this is more clean, you'll have to think abvout how to pass the data to show to the process

Upvotes: 1

Related Questions