JavaFx ProgressIndicator while Loading Pane (GUI)

后端 未结 2 548
我寻月下人不归
我寻月下人不归 2021-01-17 00:56

In my application, I have to build big panes with a lot of content. I will show a ProgressIndicator while the GUI is loading.

My first test, I will show a ProgressIn

2条回答
  •  失恋的感觉
    2021-01-17 01:35

    I have change the class like this:

    public class SampleController implements Initializable {
    @FXML
    private BorderPane borderPane;
    ProgressIndicator myProgressIndicator;
    Task> myLongTask;
    TabPane tabPane = new TabPane();
    
    @Override
    public void initialize(URL location, ResourceBundle resources)
    {
            myLongTask = new Task>()
            {
                @Override
                protected List call() throws Exception
                {
                List newTabs = new ArrayList();
                final int count = 1000 - 1;
                for (int i = 1; i <= count; i++)
                {
                    Tab newTab = new Tab("Number:" + i);
                    newTabs.add(newTab);
                }
                return newTabs;
                }
            };
    
        myProgressIndicator = new ProgressIndicator();
        myProgressIndicator.progressProperty().bind(myLongTask.progressProperty());
        borderPane.setCenter(new Pane(myProgressIndicator));
    
        new Thread(myLongTask).start();
    
        myLongTask.setOnSucceeded(evt -> {
        final List result = myLongTask.getValue();
        final int step = 5;
        final int size = result.size();
    
        AnimationTimer timer = new AnimationTimer() {
            int index = 0;
            @Override
            public void handle(long now) {
            tabPane.getTabs().addAll(result.subList(index, Math.min(size, index+step)));
            index += step;
            if (index >= size) {
                this.stop();
            }
            }
        };
            timer.start();
            borderPane.setCenter(new Pane(tabPane));
        });
    }
    

    }

    Is it this what you mean?

提交回复
热议问题