This discussion is archived
2 Replies Latest reply: Feb 5, 2013 10:48 AM by 893630 RSS

popup issue

893630 Newbie
Currently Being Moderated
I have an interesting problem. I have a popup window with a button.
The button has a setOnAction method i.e.
  btn.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent arg0) {
         some large work.
                              My expectation is when I click the btn , it should disable itself first and then go through the large work and ultimately popup hides/terminates.
          However, when I run the code, btn isn't disable in UI till the large work finishes. It acts as if step 2 has become step 1 and vice versa though on debugging I can see control passing throug step1 before step2. For some reason , UI is not updated till step 2 finishes.
          Can I get someInsight on this.

  • 1. Re: popup issue
    shakir.gusaroff Expert
    Currently Being Moderated
    Hi. I would put step 2 in a separate thread:
    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.concurrent.Task;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    public class TaskP extends Application {
        public void start(Stage primaryStage) {
           final Button btn = new Button();
            btn.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                    Thread th = new Thread(createTask());
            StackPane root = new StackPane();
            Scene scene = new Scene(root, 300, 250);
        Task<Void> createTask() {
            Task<Void> task = new Task<Void>() {
                protected Void call() throws Exception {
                    Platform.runLater(new Runnable() {
                        public void run() {
                            int iterations;
                            for (iterations = 0; iterations < 100000; iterations++) {
                                System.out.println("Iteration " + iterations);
                    return null;
            return task;
        public static void main(String[] args) {
  • 2. Re: popup issue
    893630 Newbie
    Currently Being Moderated


  • Correct Answers - 10 points
  • Helpful Answers - 5 points