mpowell48
mpowell48

Reputation: 43

How can I add a Node to an HBox inside of a Tab JavaFX?

I have a GUI that I've created, and I would like to add a ProgressIndicatorwhen the application is doing something in the background. I've created a Tab in the constructor similar to the following:

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);
    }
...

Later on, I have a button press that starts the application doing a background task, and I would like to add a ProgressIndicator to the center of the BorderPane. I tried something like the following:

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

I would think that this works, however, getContent returns a Node, and I cannot call getChildren on that Node. How can I access the BorderPane to add another Node without making the BorderPane a field in my class?

Upvotes: 0

Views: 1860

Answers (1)

James_D
James_D

Reputation: 209225

Just make the border pane an instance variable:

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));
    }
}

Upvotes: 1

Related Questions