Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Set busy cursor for a scene

2674384May 15 2014 — edited May 19 2014

Hi all,

This is the first time I post here so plz forgive me if my post in wrong format.

My problem is simple. Just set busy cursor on a scene.

The scenarios is like this: I have simple application with a button on it. When I click the button, I will:

1. Set mouse cursor to BUSY

2. Do some work

3. Set mouse cursor back to DEFAULT.

I search the web and found some sample codes to set cursor. But they don't satisfy my need. So I wrote a simple application:

public class MainFormApp extends Application {

  @Override

  public void start(Stage stage) throws Exception {

       stage.initStyle(StageStyle.DECORATED);

        Pane root = new Pane();

        root.setPrefSize(500, 300);

       

        Button btn = new Button("Click me");       

        root.getChildren().add(btn);

       

        final Scene scene = new Scene(root);

       

        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override

            public void handle(ActionEvent event) {

            // Set busy cursor

            scene.setCursor(Cursor.WAIT);

            for (int i = 0; i < 1000000; i++) {

                System.out.println("Looping " + i);

            }

            

             // Reset cursor to default           

             scene.setCursor(Cursor.DEFAULT);

          }

        });

           

       stage.setScene(scene);

       stage.show();

  }

  public static void main(String[] args) {

        launch(args);

    }

}

When I run application and click the button, cursor does not change to BUSY. I also tried to use Platform.runLater() but no luck.

Can somebody tell me what's wrong with my code and how to make it work?

Thank you in advance,

Tran

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 16 2014
Added on May 15 2014
3 comments
2,661 views