Reputation: 147
I am using JavaFX for UI.How to set Vbox layout's size to window size? I tried the below code,but couldnot view the components added in vbox.
VBox vbox = new VBox();
vbox.setPadding(new Insets(10, 10, 10, 10));
vbox.setSpacing(10);
Upvotes: 2
Views: 25552
Reputation: 111
This sets VBOX on 80% of the Stage width:
Stage window = PrimaryStage;
VBox layout = new VBox(10);
//multiply to set size (0.80 is like 80% of the window)
layout.prefWidthProperty().bind(window.widthProperty().multiply(0.80));
Upvotes: 11
Reputation: 9
You can use:
VBox vbox = new VBox();
vbox.setPrefWidth(400);// prefWidth
vbox.setPrefHeight(500);// prefHeight
or
VBox vbox = new VBox();
vbox.setPrefSize(400, 500);// prefWidth, prefHeight
Read more here!
Upvotes: -6
Reputation: 4352
primaryStage.setScene(new Scene(vBox, 200, 200));
vBox.getChildren().add(label);
Try this example:
package javafxapplication1;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class JavaFXApplication1 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
VBox vBox = new VBox();
vBox.setStyle("-fx-background-color: #ABABAB");
Label label = new Label("Test");
vBox.getChildren().add(label); //Add new node to vBox
primaryStage.setScene(new Scene(vBox, 200, 200)); //Add vbox to scene
primaryStage.show();
}
}
Upvotes: -3