Button button = new Button("Show Text");
button.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
Platform.runLater(new Runnable(){
@Override
public void run() {
field.setText("START");
}
});
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
Platform.runLater(new Runnable(){
@Override
public void run() {
field.setText("END");
}
});
}
});
运行上面的代码后,field.setText("START")
不执行,我的意思是文本框没有其文本设置为“START”,为什么?如何解决这个问题?Platform.runLater问题 - 延迟执行
相关链接:[JavaFX的8:如何将添加纯滞后的听众(http://stackoverflow.com/questions
您可以在一个新的线程运行上面的所有代码解决这个问题/ 34784037/javafx-8-how-to-add-a-timedelay-to-a-listener)和[等待改变属性后改变JavaFX 8](http://stackoverflow.com/questions/22263008/wait- before-react-to-a-property-change-javafx-8) – jewelsea