我想更改te光标等待用户打开新阶段时此阶段仅用于拍摄快照然后在默认系统程序中打开此快照用于图像,这通常需要10个secons whitch并不多它阻碍了用户体验。
这是我调用新阶段的代码,我尝试更改光标
public void imprimirConsulta(){
//change the cursor to wait
stage.getScene().setCursor(Cursor.WAIT);
//crate a task for a new thread
Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
Platform.runLater(new Runnable(){
public void run(){
/*take from a tableview row the object
that has the information for the new stage*/
consul = tvConsulta.getSelectionModel().getSelectedItem();
//launch the new stage
hEstadistica.ImpreConsul(true, consul);
}
});
return null;
}
};
//when finish the task change the cursor to the default style
task.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
@Override
public void handle(WorkerStateEvent event) {
stage.getScene().setCursor(Cursor.DEFAULT);
}
});
//star the new thread
Thread tt = new Thread(task);
tt.setDaemon(true);
tt.start();
}
新阶段立即关闭此代码
public void initialize(URL url, ResourceBundle rb) {
PauseTransition delay = new PauseTransition(Duration.seconds(1));
delay.setOnFinished( event -> stage.hide());
delay.play();
}
快照将使用此代码
WritableImage snapshot = stage.getScene().snapshot(null);
File file = new File("src//HE//Utilidades//Imagenes//consul.png");
try {
ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", file);
Desktop dt = Desktop.getDesktop();
dt.open(file);
} catch (IOException e) {
e.printStackTrace();
}
我正在使用文件FXML,这是加载对嵌入式SQLite数据库进行SQL查询的新阶段,但它非常简单,只涉及文本,事件是从TableView中的ContextMenu启动的,这个阶段显示并使用默认系统程序打开快照图像,但光标不会更改。
如何让光标改变状态?