1

我对 Javafx 很陌生,我现在面临一个问题。我想将控件添加到边框窗格中。所以我这样做了:

borderPane.setLeft(label1);

当我尝试在旁边放置另一个标签时label1,我这样做了:

borderPane.setLeft(label2);

但它取代了label1. 我希望他们并肩而行。我该怎么做?

4

1 回答 1

2

您不能在BorderPane. 如果需要添加多个控件,则需要使用 Container,例如HBox

  • HBox 将孩子按水平顺序放置
  • VBox 以垂直顺序放置孩子

向其中添加两个标签,然后将 HBox 添加到 BorderPane 的左侧。

HBox box = new HBox();
box.getChildren.addAll(label1, label2);
borderPane.setLeft(box);
于 2015-03-10T07:54:17.457 回答