Ron
Ron

Reputation: 1336

JavaFX 2.0: Flowpane should automaticly resize when parental element does

In JavaFX 1.x, where I've used the FX-Script to setup the Scene, I had the bind keyword:

Dynamic/instant resize in JavaFX

How can I have the same behavior in 2.0?

Upvotes: 2

Views: 9280

Answers (3)

Peter Lamberg
Peter Lamberg

Reputation: 8651

If your flow pane has margins, you need perhaps something like this:

  innerHorizontalFlowPane.prefWidthProperty().bind(
      Bindings.add(-50, stage.widthProperty()))

Upvotes: 0

Sandro
Sandro

Reputation: 66

If you want automatic resize, you should do something like this

private BorderPane root;

@Override
public void start(Stage stage) throws Exception
{
   root = new BorderPane();
    //ROOT SHOULD BE ONE OF THE LAYOUTS : BorderPane, HBox, VBox, StackPane,     
    //GridPane, FlowPane
    scene = new Scene(root, 500, 500);

    stage.setScene(scene);

    stage.show();
    root.setCenter(new Label("sample label"));
}

I have tried only with BorderPane and it works. Also if you want to create custom component, your class should extend one of layouts. Automatic resize won't work if your component extends Pane or Group

I think this will help to you.

Best regards Sandro

Upvotes: 5

Ron
Ron

Reputation: 1336

I've just found the answer on another plattform:

It is as easy as

FlowPane layout=new FlowPane();
layout.prefWidthProperty().bind(stage.widthProperty());
layout.prefHeightProperty().bind(stage.heightProperty());

Upvotes: 5

Related Questions