有在应用层面做到这一点(我知道的),没有直接的方法。但是,游标是一个属性,因此您可以将所有场景的游标绑定到单个值。
因此,像:
public class MyApp extends Application {
private final ObjectProperty<Cursor> cursor = new SimpleObjectProperty<>(Cursor.DEFAULT);
@Override
public void start(Stage primaryStage) {
Parent root = ... ;
// ...
someButton.setOnAction(event -> {
Parent stageRoot = ... ;
Stage anotherStage = new Stage();
anotherStage.setScene(createScene(stageRoot, ..., ...));
anotherStage.show();
});
primaryStage.setScene(createScene(root, width, height));
primaryStage.show();
}
private static Scene createScene(Parent root, double width, double height) {
Scene scene = new Scene(root, width, height);
scene.cursorProperty().bind(cursor);
return scene ;
}
}
现在,任何时候你做
cursor.set(Cursor.WAIT);
通过createScene(...)
方法将改变其光标创建任何场景。
显然光标属性和实用方法没有在应用程序的子类来定义;你可以把它们放在你的应用程序结构方便的地方。