I have a JavaFX 2.0 application with FXML. I want the components (TextFields, ComboBoxes, layouts, and so on) to be resized when a window with an application is resized. So
Another easy option is to use JavaFX Scene Builder (recently become available as public beta: http://www.oracle.com/technetwork/java/javafx/tools/index.html)
It allows to create UI by drag-and-drop and anchor UI elements to borders (by anchor tool), so they move/resize with the window borders.
UPDATE:
To achieve autoresizing percentage layout you can use GridPane
with ColumnConstraint
:
public void start(Stage stage) {
VBox box1 = new VBox(1);
VBox box2 = new VBox(1);
//random content
RectangleBuilder builder = RectangleBuilder.create().width(20).height(20);
box1.getChildren().addAll(builder.build(), builder.build(), builder.build());
builder.fill(Color.RED);
box2.getChildren().addAll(builder.build(), builder.build(), builder.build());
//half by half screen
GridPane grid = new GridPane();
grid.addRow(0, box1, box2);
ColumnConstraints halfConstraint = ColumnConstraintsBuilder.create().percentWidth(50).build();
grid.getColumnConstraints().addAll(halfConstraint, halfConstraint);
stage.setScene(new Scene(grid, 300, 250));
stage.show();
}
Some suggestions for building resizable guis =>
Here is an example of a resizable JavaFX UI which implements some of the principles above.
Suggestions: