java打开另一个阶段JavaFX时将光标更改为等待
我想将光标更改为用户打开新阶段时等待此阶段仅用于拍摄快照,然后在默认系统程序中打开此快照以获取图像,这通常需要10秒,这并不多,但会妨碍用户体验
这是我调用新阶段的代码,我尝试在其中更改光标
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启动,阶段显示,快照图像用默认系统程序打开,但光标不变
如何使光标改变状态
共 (0) 个答案