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