【发布时间】:2016-05-30 09:02:54
【问题描述】:
你能解释一下如何刷新标签中的值吗?
在初始化时,我将 Label 的文本绑定到 StringProperty。这里没问题。
我有按钮,按下按钮时我想在每个迭代步骤中更新标签值。 但我只能看到最终值。为什么?
@FXML
private Label label;
@FXML
private void handleButtonAction(ActionEvent event) throws InterruptedException {
for(int i=0;i<1001;i++){
try {
Thread.sleep(1);
} catch (InterruptedException ie) {
//Handle exception
}
this.value.setValue(i+"");
}
}
// Bind
private StringProperty value = new SimpleStringProperty("0");
@Override
public void initialize(URL url, ResourceBundle rb) {
// Bind label to value.
this.label.textProperty().bind(this.value);
}
【问题讨论】: