Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:54:54+00:00 2026-06-07T05:54:54+00:00

My application is Swing-based. I would like to introduce JavaFX and configure it to

  • 0

My application is Swing-based. I would like to introduce JavaFX and configure it to render a Scene on a secondary display.
I could use a JFrame to hold a JFXPanel which could hold a JFXPanel but I would like to achieve this with JavaFX API.

Subclassing com.sun.glass.ui.Application and using Application.launch(this) is not an option because the invoking thread would be blocked.

When instantiating a Stage from Swing EDT, the error I get is:

java.lang.IllegalStateException: Toolkit not initialized

Any pointers?


EDIT: Conclusions

Problem: Non-trivial Swing GUI application needs to run JavaFX components. Application’s startup process initializes the GUI after starting up a dependent service layer.

Solutions

Subclass JavaFX Application class and run it in a separate thread e.g.:

public class JavaFXInitializer extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        // JavaFX should be initialized
        someGlobalVar.setInitialized(true);
    }
}

Sidenote: Because Application.launch() method takes a Class<? extends Application> as an argument, one has to use a global variable to signal JavaFX environment has been initialized.

Alternative approach: instantiate JFXPanel in Swing Event Dispatcher Thread:

final CountDownLatch latch = new CountDownLatch(1);
SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        new JFXPanel(); // initializes JavaFX environment
        latch.countDown();
    }
});
latch.await();

By using this approach the calling thread will wait until JavaFX environment is set up.

Pick any solution you see fit. I went with the second one because it doesn’t need a global variable to signal the initialization of JavaFX environment and also doesn’t waste a thread.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:54:56+00:00Added an answer on June 7, 2026 at 5:54 am

    Found a solution. If I just create a JFXPanel from Swing EDT before invoking JavaFX Platform.runLater it works.
    I don’t know how reliable this solution is, I might choose JFXPanel and JFrame if turns out to be unstable.

    public class BootJavaFX {
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    new JFXPanel(); // this will prepare JavaFX toolkit and environment
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            StageBuilder.create()
                                    .scene(SceneBuilder.create()
                                            .width(320)
                                            .height(240)
                                            .root(LabelBuilder.create()
                                                    .font(Font.font("Arial", 54))
                                                    .text("JavaFX")
                                                    .build())
                                            .build())
                                    .onCloseRequest(new EventHandler<WindowEvent>() {
                                        @Override
                                        public void handle(WindowEvent windowEvent) {
                                            System.exit(0);
                                        }
                                    })
                                    .build()
                                    .show();
                        }
                    });
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a simple java swing based application. How would I get
I'd like to add persistence to my Swing-based application; and this is the first
I'm making a swing based application where I have a JList that periodically get's
I am planning to write a Swing-based application (using Netbeans 6.8). It seems that
We have a problem in our swing based application since we've upgraded our java
Background: I have written a java swing based client server application. The server is
I have to setup a basic JAVA application including a GUI based on swing.
I had made one Java Swing based application. On my application,if i click anywhere
Developing a desktop application based on Java + Swing I faced the problem of
I have a server application and two Swing-based client applications. We're developing them in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.