Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 821
Ron Avatar asked Dec 30 '25 13:12

Ron


1 Answers

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

like image 93
Sandro Avatar answered Jan 03 '26 05:01

Sandro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!