Changing mouse cursor for long actions in JavaFX

63 views Asked by At

I know that there are questions about this here, but I couldn't find any solution for my problem.

public void markEpisodeAsWatched() {

        getStage().getScene().setCursor(Cursor.WAIT);
//      Platform.runLater(new Runnable() {
//        @Override
//        public void run() {
              try {
                showTaggedShows();
            } catch (SQLException e) {
                e.printStackTrace();
            }
              getStage().getScene().setCursor(Cursor.CROSSHAIR);
//        }
//      });



    }

Method markEpisodeAsWatched is called upon a click on a button and I can't find out how to change cursor before it starts showTaggedShows method, after this action is done my cursor only then changes to CROSSHAIR. As you can see I've tried already with Platform.runLater(), but it seems I don-t know how to implement it, it didn't change anything.

Thank you for your help!

Solution: Thanks to James_D who pointed me to the right answer

scene.setCursor(Cursor.WAIT);
        Task<Void> task = new Task<Void>() {
            @Override
            public Void call() {
                try {
                    showTaggedShows();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return null ;
            }
        };
        task.setOnSucceeded(e -> scene.setCursor(Cursor.CROSSHAIR));
        new Thread(task).start();
0

There are 0 answers