Reputation: 71
I am trying to practice with BorderPanes, which so far has been a nightmare. I have tried to get my label to just show up in the window with no avail. Any ideas?
Label arrayLabel = new Label("NUMBERS");
BorderPane.setAlignment(arrayLabel, Pos.TOP_CENTER);
TextField search = new TextField();
Button btn = new Button("search");
HBox searchbox = new HBox(2);
searchbox.getChildren().addAll(search, btn);
searchbox.setAlignment(Pos.CENTER);
BorderPane root = new BorderPane(arrayLabel);
root.setPrefSize(600, 600);
root.setCenter(searchbox);
Upvotes: 0
Views: 448
Reputation: 209319
A BorderPane
can only have one node in any region. (That node, of course, could be a parent containing arbitrary numbers of other nodes.) The constructor taking a single parameter treats that parameter as the node to be displayed in the center.
So
BorderPane root = new BorderPane(arrayLabel);
is equivalent to
BorderPane root = new BorderPane();
root.setCenter(arrayLabel);
When you subsequently (immediately) then call
root.setCenter(searchbox);
the center node is replaced by searchbox
, so arraylabel
is no longer part of the BorderPane
.
It's not really clear what you intend here: you are essentially trying to put two different UI components (arrayLabel
and searchbox
) into the same region of the same BorderPane
. There's no information (provided either to us, or to the poor BorderPane
who is trying to position these nodes) as to how you want these two components positioned relative to each other. What are you actually trying to achieve, in terms of how you want these laid out?
Upvotes: 4