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