Evans Belloeil
Evans Belloeil

Reputation: 2503

How to make layout's content resizable?

I've create this in scene builder :

Terminal

Terminal Hierarchy

My goal is to make this a little more beautiful :

To do so I want to manipulate the layout properties, but I don't really know how. I was thinking of using spacing for my problem one, but it seems complicated, and I have no idea for resolving my second problem.

Is the choice of my layout correct ? What properties do I have to use for resolving my problems ?

Thanks.

Upvotes: 0

Views: 119

Answers (1)

Uluk Biy
Uluk Biy

Reputation: 49185

IMO using StackPane for top layout is more appropriate:

@Override
public void start( Stage stage )
{
    Button b = new Button( "Close" );
    Label l = new Label( "Console" );

    StackPane sp = new StackPane( l, b );
    StackPane.setAlignment( l, Pos.CENTER_LEFT );
    StackPane.setAlignment( b, Pos.CENTER_RIGHT );

    TextArea area = new TextArea();
    VBox.setVgrow( area, Priority.ALWAYS );
    VBox box = new VBox( sp, area );

    Scene scene = new Scene( box, 800, 600 );

    stage.setScene( scene );
    stage.show();
}

But using of HBox is unavoidable, add another element to it as a spacer:

@Override
public void start( Stage stage )
{
    Button b = new Button( "Close" );
    Label l = new Label( "Console" );
    Pane spacer = new Pane();

    HBox hBox = new HBox(l, spacer, b);
    HBox.setHgrow( spacer, Priority.ALWAYS);

    TextArea area = new TextArea();
    VBox.setVgrow( area, Priority.ALWAYS );
    VBox box = new VBox( hBox, area );

    Scene scene = new Scene( box, 800, 600 );

    stage.setScene( scene );
    stage.show();
}

Upvotes: 1

Related Questions