FlowPane和定位

时间:2016-01-18 15:46:28

标签: java javafx-8 panes

是否可以通过以下方式使用flowpane? 将两个组件(img / label)对齐到左侧,然后在右侧对齐多个按钮。例如:

    +----------------------------------------------------------------+
    | +------+ +----------+                          +-----+ +-----+ |
    | |  Img | | Text...  |                          | btn | | btn | |
    | +------+ +----------+                          +-----+ +-----+ |
    +----------------------------------------------------------------+

我正在添加设计/易用性的按钮,但我遇到了砖墙。我宁愿不必更改“保持面板”。

如果不能在css中模拟(浮动?)

由于

2 个答案:

答案 0 :(得分:0)

是的!

myFlow.add(griddy); // this gridlayout contains img and text
myFlowcontainer.add(Box.createRigidArea(new Dimension(5,0))); // Creating a space between. 
The actual size will be defined by you
myFlow.add(griddy2); // The other element with the btn btn

这应该能够达成协议;)

答案 1 :(得分:0)

FlowPane可以设置边距。 Here是一个示例,显示如何计算边距的宽度,以便按钮右对齐。

scene.widthProperty().addListener( ( observable, oldWidth, newWidth ) ->
{
  final double spacerMargin = newWidth.doubleValue()
      - scene.getRoot().getChildrenUnmodifiable().stream().mapToDouble( node -> node.getLayoutBounds().getWidth() ).sum();
  FlowPane.clearConstraints( btn3 );
  FlowPane.setMargin( btn3, new Insets( 0, 0, 0, spacerMargin ) );
} );

您基本上从场景的宽度中减去FlowPane子项的所有宽度。