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

  • SEARCH
  • Home
  • 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 8489679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:53:42+00:00 2026-06-10T21:53:42+00:00

I have a problem with opening one more stage in another thread. No exceptions

  • 0

I have a problem with opening one more stage in another thread. No exceptions appears if I’m opening this stage in the same thread.

void hashMapDeclaration(){
    actions2methods.put("NEW", new Runnable() {@Override public void run() { newNetCreation(); }});
    actions2methods.put("LOAD", new Runnable() {@Override public void run() { loadNetState(); }});
    ......  //other hashes
}

HBox buttonBuilder(double spacing,double layoutX,String... bNames){
    HBox lBar = new HBox(10);
    .... //some code
    for(final String text : bNames){ //in my case text variable value is "NEW" so it should run method newNetCreation
        Button newButton = new Button();
        newButton.setText(text);
        .... //code
        newButton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent paramT) {
                Thread t;
                EventQueue.isDispatchThread();
                t = new Thread(actions2methods.get(text));
                t.start(); // Start the thread 
                System.out.println("button pressed");
            }
        });
        lBar.getChildren().add(newButton);
    }
    return lBar;
}

void newNetCreation(){
    final Stage dialogStage = new Stage();
    final TextField textField;
    dialogStage.initOwner(stage);
    dialogStage.initModality(Modality.WINDOW_MODAL);   
    dialogStage.setFullScreen(false);
    dialogStage.setResizable(false);
    dialogStage.setScene(SceneBuilder
        .create()
        .fill(Color.web("#dddddd"))
        .root(textField = TextFieldBuilder
                            .create()
                            .promptText("Enter user name")
                            .prefColumnCount(16)
                            .build()
        )
        .build()
    );
    textField.textProperty().addListener(new ChangeListener() {
        public void changed(ObservableValue ov, Object oldValue, Object newValue) {
            System.out.println("TextField text is: " + textField.getText());
        }
    });
    dialogStage.show();
    System.out.println("new net");
}

Method newNetCreation is the one that cause the problem. All actions in my program are store in a HashMap. Method buttonBuilder creates the new thread and should launch methods according to variable value and in my case he must call newNetCreation method, but when he tries, the following exception occurs:

Exception in thread "Thread-3" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-3
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(Unknown Source)
at javafx.stage.Stage.<init>(Unknown Source)
at javafx.stage.Stage.<init>(Unknown Source)
at projavafx.starterapp.ui.StarterAppMain.newNetCreation(StarterAppMain.java:400)
at projavafx.starterapp.ui.StarterAppMain$7.run(StarterAppMain.java:354)
at java.lang.Thread.run(Thread.java:722)
  • 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-10T21:53:44+00:00Added an answer on June 10, 2026 at 9:53 pm

    All UI operation for JavaFX should be perfromed on FX application thread.

    Here is your code:

      Thread t; 
      t = new Thread(actions2methods.get(text));
      t.start(); // Start the thread 
    

    t is thread which you runs your method on. It’s obviously not FX thread as stated in log your provided: java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-3

    If you want to run Runnable on FX thread, use next code:

      Platform.runLater(actions2methods.get(text));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem here with this code. I'm opening a socket, then listening
I have a problem with opening CF.NET forms using VSTS 2008. It uses the
I have a problem with IE8 and the opening of a new window with
well I have that problem, im using a lightbox srcipt and im opening an
I have problem with my query on C, I’m using the oci8 driver. This
Problem : I have multiple instances of the same C# application running on different
I have this problem: I have a collection of small files that are about
I have an issue with a simple program. I'm opening a QFileDialog this way:
I sometimes have a problem with opening UIDocuments which are stored on iCloud. I
Hi all I have a problem with CSV opening through PHP code. My PHP

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.