如何在选项卡Javafx内部的Hbox中添加一个节点



我有我创建的GUI,并且当应用程序在后台做某事时,我想添加ProgressIndicator。我在构造函数中创建了一个 Tab,类似于以下内容:

public class myGUI {
    Tab myTab;
    myGUI() {
        myTab = new Tab("My Tab");
        HBox view = new HBox();
        VBox left = new VBox();
        BorderPane right = new BorderPane();
        /*A lot of other things are declared that go in left and right*/
        view.getChildren().addAll(left, right);
        myTab.setContent(view);
    }
...

稍后,我有一个按钮按下执行背景任务的应用程序,我想将ProgressIndicator添加到BorderPane的中心。我尝试了以下内容:

private void handleMyAction(MouseEvent e) {
    myTab.getContent().getChildren().get(1).setCenter(new ProgressIndicator(-1.0f));
}

我认为这有效,但是,getContent返回Node,并且我无法在该Node上调用getChildren。如何访问BorderPane以添加另一个Node,而无需使BorderPane在我的班级中成为字段?

只需使边界窗格变量:

public class MyGUI {
    private Tab myTab;
    private BorderPane right ;
    MyGUI() {
        myTab = new Tab("My Tab");
        HBox view = new HBox();
        VBox left = new VBox();
        right = new BorderPane();
        /*A lot of other things are declared that go in left and right*/
        view.getChildren().addAll(left, right);
        myTab.setContent(view);
    }
    private void handleMyAction(MouseEvent e) {
        right.setCenter(new ProgressIndicator(-1.0f));
    }
}

最新更新