Yin
Yin

Reputation: 415

How can I add controls into Borderpane in Javafx?

I'm very new to Javafx and I'm facing a problem right now. I want to add controls into a borderpane. So I did this:

borderPane.setLeft(label1);

And when I try placing another label beside label1, I did this:

borderPane.setLeft(label2);

But it replaces label1. I want them to be side by side. How should I do that?

Upvotes: 1

Views: 1744

Answers (1)

ItachiUchiha
ItachiUchiha

Reputation: 36792

You can't add two controls in a single space of BorderPane. If you need to add multiple controls you need to use a Container, such as a HBox.

  • HBox places the children in horizontal order
  • VBox places the children in vertical order

Add both labels to it, and then add the HBox to the left side of the BorderPane.

HBox box = new HBox();
box.getChildren.addAll(label1, label2);
borderPane.setLeft(box);

Upvotes: 2

Related Questions