プログラムがビジーであることを示すカーソルを変更しようとしています。これはかなり単純なはずですが、正しく動作させることができず、数時間検索しても解決策が見つかりませんでした. これが私がやろうとしていることです。
public class ButtonTest extends Application {
@Override
public void start(Stage primaryStage) {
final StackPane root = new StackPane();
primaryStage.setScene(new Scene(root, 200, 150));
Button button = new Button();
button.setText("Button");
root.getChildren().add(button);
primaryStage.show();
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// Set the cursor to the wait cursor.
root.setCursor(Cursor.WAIT);
// Do some work.
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Set the cursor back to the default.
root.setCursor(Cursor.DEFAULT);
}
});
}
public static void main(String[] args) {
launch(args);
}
}
setCursor(Cursor.DEFAULT) をコメントアウトすると、ボタンを押した後、5 秒間待機してから、カーソルが待機カーソルに変わります。そのため、スリープ後まで待機してから setCursor(Cursor.WAIT) を実行し、その直後に setCursor(Cursor.DEFAULT) を実行しているようです。私は何が欠けていますか?