0

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();
user3746480
  • 333
  • 5
  • 17
  • 1
    You need to run the `showTaggedShows()` method on a background thread. See, e.g. http://stackoverflow.com/questions/26554814/javafx-updating-gui – James_D Dec 18 '16 at 15:22
  • James_D thank you for answer, but I had no luck with this example, Ive never used multi threading before so I'm a little confused; shouldn't I have to run setting cursor in different thread rather that running showTaggedShows in different thread? Could you write me an example for my piece of code? – user3746480 Dec 18 '16 at 16:00
  • 1
    The are already dozens of examples of what you are asking on this site. You cannot change the UI (which includes changing the cursor) from a background thread. – James_D Dec 18 '16 at 16:35

0 Answers0