节点之间的BorderPane间距

Reu*_*ers 12 layout javafx javafx-8

是否可以在节点之间设置间距BorderPane?Swing等效的是hgap和vgap BorderLayout.

我没有在文档中找到任何内容,我能想到的唯一可行的解​​决方法是有选择地在子节点上设置边距以复制效果.

Fou*_*pie 9

Insets insets = new Insets(10);
BorderPane bp = new BorderPane();

Node topNode = new Label("TOP");
bp.setTop(topNode);
BorderPane.setMargin(topNode, insets);

Node centerNode = new Label("CENTER");
bp.setCenter(centerNode);
BorderPane.setMargin(centerNode, insets);

Node bottomNode = new Label("BOTTOM");
bp.setBottom(bottomNode);
BorderPane.setMargin(bottomNode, insets);
Run Code Online (Sandbox Code Playgroud)

请注意:这将在顶部和中心之间留出20的间距(顶部距离10,中央距离10)。中心和底部之间的间距相似。

该文件

公共静态无效setMargin(Node child,Insets value)

设置由边框窗格包含时的子项的边距。如果设置,则边框窗格将使用周围的空白空间对其进行布局。将值设置为null将删除约束。


Tho*_*att -4

可以设置填充:

在 JFX 中:

<BorderPane>
   <padding>
      <Insets top="10" right="10" bottom="10" left="10"/>
   </padding>
</BorderPane>
Run Code Online (Sandbox Code Playgroud)

在代码中:

@FXML
private BorderPane borderPane;    
...
this.borderPane.setPadding(new Insets(10, 10, 10, 10));
Run Code Online (Sandbox Code Playgroud)

  • 这不会在元素之间设置间隙。 (3认同)