Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JavaFX中更新组件GUI_Java_User Interface_Javafx - Fatal编程技术网

在JavaFX中更新组件GUI

在JavaFX中更新组件GUI,java,user-interface,javafx,Java,User Interface,Javafx,我需要从javafx中的句柄函数更新一些组件(标签、ProgressBar、按钮) 该对话框是一个模态对话框,用于按顺序执行某些操作 @FXML public void updateHandle(ActionEvent action){ buttonSend.setDisable(true); /* Operation 1 */ progressBar.setProgress(0.05); label.setText("Init.."); myIn

我需要从javafx中的句柄函数更新一些组件(标签、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);
   });
}