0

I have to launch a JavaFx application on a click of a JMenuItem of a tree node which extends JApplet class and runs on Swing JFrame window.

I had gone through the tutorials on JavaFx in Swing applications https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm and this question Run javafx and swing application at the same time and understood that I have to work JavaFx data on JavaFx application thread.

So I tired to launch the JavaFx application through Platorm.runlater thread on the click of the JMenuItem and made sure that the JavaFx application implements Runnable interface but still I encountered this error : ToolKit not initialized.

Here is the sample code of JMenuItem that launches JavaFx Application

    static class OpenJavaFxApp extends JMenuItem{
    OpenJavaFxApp(){   
       super("JavaFx App");
        // This should launch JavaFx app
       this.addActionListner(actionEvent -> Platform.runLater(() ->{
                try{
                     // JavaFx app extends Application and 
                     //impelents Runnable 
                     JavaFxApp app = new JavaFxApp;
                     Stage anotherstage = new Stage();
                     app.start(anotherstage);
                     } catch(Exception e){
                         e.printstacktrace();
                         }
                   })
             );
         }
     }

Sample JavaFx app code

     public class JavaFxApp extends Application implements Runnable{

        @Override
        public void start(Stage primaryStage){
          AnchorPane pane = new AnchorPane();
          pane.getChildren().addall(AddSomething);
          Scene scene = new Scene(pane);
          primaryStage.setScene(scene);
          primaryStage.show();
        }

        public static void main(Strings[] args){
              launch(args);
        }

        @Override
        public void run(){
             launch();
        }
      }

Please be a little bit specific with your solution but any help is appreciated. Thanks:)

Kiran_KKT
  • 1
  • 3

0 Answers0