如何在 Javafx 中将控件添加到 BorderPane 中?
How can I add controls into Borderpane in Javafx?
我是 Javafx 的新手,现在遇到了一个问题。
我想将控件添加到边框窗格中。所以我这样做了:
borderPane.setLeft(label1);
当我尝试在 label1
旁边放置另一个标签时,我这样做了:
borderPane.setLeft(label2);
但它取代了label1
。我希望他们并肩。我应该怎么做?
您不能在 BorderPane
. If you need to add multiple controls you need to use a Container, such as a HBox 的单个 space 中添加两个控件。
- HBox 将子项按水平顺序排列
- VBox 以垂直顺序放置子项
将两个标签都添加到它,然后将 HBox 添加到 BorderPane 的左侧。
HBox box = new HBox();
box.getChildren.addAll(label1, label2);
borderPane.setLeft(box);
我是 Javafx 的新手,现在遇到了一个问题。 我想将控件添加到边框窗格中。所以我这样做了:
borderPane.setLeft(label1);
当我尝试在 label1
旁边放置另一个标签时,我这样做了:
borderPane.setLeft(label2);
但它取代了label1
。我希望他们并肩。我应该怎么做?
您不能在 BorderPane
. If you need to add multiple controls you need to use a Container, such as a HBox 的单个 space 中添加两个控件。
- HBox 将子项按水平顺序排列
- VBox 以垂直顺序放置子项
将两个标签都添加到它,然后将 HBox 添加到 BorderPane 的左侧。
HBox box = new HBox();
box.getChildren.addAll(label1, label2);
borderPane.setLeft(box);