是否可以在BorderPane上的节点之间设置间距?在BorderLayout上,等效于Swing的将是hgap和vgap。

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

最佳答案

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);

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

公共静态无效setMargin(Node child,Insets value)
设置由边框窗格包含时的子项的边距。如果设置,则边框窗格将使用周围的空白空间对其进行布局。将值设置为null将删除约束。

10-08 03:33