I am currently trying to learn JavaFX. I have created a small setup with a Gridpane shown in the screenshot below
I made the background of the gridpane red so as you can see it fills the whole screen. But unfortunately the labels and textfields stay the same size. I want them to scale with the size of the gridpane.
Below is the code at the moment:
@Override
public void start(Stage primaryStage) throws Exception{
primaryStage.setTitle("Test Application");
grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(10, 10, 10, 10));
grid.setPrefSize(WINDOW_WIDTH, WINDOW_HEIGHT);
grid.setMinSize(WINDOW_WIDTH, WINDOW_HEIGHT);
textWelcome = new Text("Welcome");
textWelcome.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
grid.add(textWelcome, 0, 0, 2, 1);
labelName = new Label("User Name: ");
grid.add(labelName, 0,1);
nameField = new TextField();
grid.add(nameField, 1,1);
labelPW = new Label("Password: ");
grid.add(labelPW,0,2);
pwField = new PasswordField();
grid.add(pwField,1,2);
buttonSign = new Button("Sign in");
HBox hBox = new HBox(10);
hBox.setAlignment(Pos.BOTTOM_RIGHT);
hBox.getChildren().add(buttonSign);
grid.add(hBox,1,3);
grid.setStyle("-fx-background-color:red");
//grid.setGridLinesVisible(true);
scene = new Scene(grid, WINDOW_WIDTH, WINDOW_HEIGHT);
primaryStage.setScene(scene);
primaryStage.show();
}
So now i want to know on how to make the whole thing scale up so that there is not a big margin at the sides.