繁体   English   中英

更新JavaFX中的组件GUI

[英]Update components GUI in JavaFX

我需要从javafx中的handle函数更新一些组件(标签,ProgressBar,按钮)。

该对话框是模式对话框,用于顺序执行某些操作。

@FXML public void updateHandle(ActionEvent action){

    buttonSend.setDisable(true);

    /* Operation 1 */ 
    progressBar.setProgress(0.05);
    label.setText("Init..");

    myInitFunction();
    myVar = new var(); //global


    /* Op2 */
    progressBar.setProgress(0.10);
    label.setText("Check connection..");

    myConnFunction();

    // ....
    // ....
}

问题是我的所有功能均已正确处理,但GUI上的元素未更改。

编辑

我尝试使用Platform.runlater,但似乎不起作用...

void updateLabelLater(final Label label, final String text) {
        Platform.runLater(new Runnable() {
          @Override public void run() {
            label.setGraphic(null);
            label.setText(text);
          }
        });
    }
void updateProgressBar(final ProgressBar progressBar, final double val){
    Platform.runLater(new Runnable() {
          @Override public void run() {
            progressBar.setProgress(val);
          }
        });
}

updateHandle是否在事件线程上运行? 由于工具问题,我没有理会FXML,所以这并不是一个解决方案。 (但希望有帮助!)

//Pseudo Code
public doLongRuningOperation(final Object ... objects){
  final Thread longRunning = new Thread(){
    public void run(){
       update("this");
       sleep(1000); //Pause/do something etc...
       update("should");
       sleep(1000);
       update("update");
       System.err.println("completed");
    }
  };
  longRunning.start(); //Start this process
}
//Rejoin the UI Thread and update it...
public void update(final String text){
   //reference to label 'lbl'
   Platform.runLater(new Runnable(){
     lbl.setText(text);
   });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM