0

Is it possible to use a flowpane in the following way? Have two components (img/label) aligned to the left and then multiple buttons on the right. Example:

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

I am adding the buttons for design / ease of use but am running into a brick wall. I would prefer not to have to change the 'holding panel'.

If not can it be simulated in css (float?)

Thanks

Ian C
  • 71
  • 2
  • 7
  • I don't see a way to do this using a `FlowPane`. It's kind of contrary to the idea of a "flow"... In JavaFX, CSS is basically used for the look of the nodes, not for layout (as it is in HTML). This probably works best using a combination of either an `AnchorPane` or `BorderPane` and a couple of `HBox`es. But maybe someone else can see a way to do this. – James_D Jan 18 '16 at 22:50

2 Answers2

1

A FlowPanecan set margins. Here is an example that shows how to calculate the width of the margin so that the buttons are right aligned.

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

You basically subtract all the widths of the children of the FlowPane from the width of your scene.

Oliver Jan Krylow
  • 1,758
  • 15
  • 22
0

Yes it is!

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

That should seal the deal ;)

Vancold.at
  • 138
  • 7
  • `Box.createRigidArea(...)` doesn't create a JavaFX `Node`, it creates a Swing component. – James_D Jan 18 '16 at 22:45
  • Okay i didn't see the JavaFX tag. Now i do :p. That is correct it doesn't create JavaFX Node. I just wrote down a gernal approach :p – Vancold.at Jan 20 '16 at 09:47