-1

以下是我在 fxml 中所做的更改

java文件的变化,这里是我的代码:

private ProgressIndicator pi;

void handlebuildButtonAction(ActionEvent event) throws IOException, GeneralSecurityException {

if ((entServer.isSelected()==true || compasServer.isSelected()==true)) {

            if(!fileList.isEmpty()){
                ProgressIndicator pi = new ProgressIndicator();
                pi.setProgress(10);
}
}

运行应用程序时进度指示器未更新。我不确定如何将更改同步到 UI。在这方面帮助我。提前致谢。

输出

4

1 回答 1

0

例如:如果您设置 0.1 - 进度将是 10%,0.2 - 20% 等等,所以当您设置进度 => 1 时,您将始终“完成”。

在这里,这是一个带有按钮的示例,当您单击按钮时,您的进度指示器将被更新(单击 + 10%):

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.stage.Stage;

public class Test extends Application {
    private ProgressIndicator pi;
    private double counter = 0;
    public void start(Stage stage)
    {
        ProgressIndicator pi = new ProgressIndicator();
        Button button = new Button("Press");

        TilePane root = new TilePane();

        // action event
        EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
            public void handle(ActionEvent e)
            {
                counter += 0.1;
                pi.setProgress(counter);
            }
        };


        button.setOnAction(event);

        root.getChildren().add(button);
        root.getChildren().add(pi);

        // create a scene
        Scene scene = new Scene(root, 200, 200);

        // set the scene
        stage.setScene(scene);

        stage.show();
    }

    public static void main(String args[])
    {
        // launch the application
        launch(args);
    }
}

只需根据您的情况更改此代码:

EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
            public void handle(ActionEvent e)
            {
                if ((entServer.isSelected()==true || compasServer.isSelected()==true)) {

                    if (!fileList.isEmpty()) {
                         counter += 0.1;
                         pi.setProgress(counter);
                    }
                }
            }
        };

希望对你有帮助!

于 2020-06-07T09:34:16.317 回答