Я создал файл fxml следующим образом:
Код: Выделить всё
Код: Выделить всё
public class DynamicResizeController {
@FXML
private VBox vBox;
@FXML
private AnchorPane rootPane;
public void handleAddButtonClick(ActionEvent event) {
Label label = new Label("New Element added!");
vBox.getChildren().add(label);
calculateAndResize();
}
private void calculateAndResize() {
double totalHeight = 0;
for (Node child : vBox.getChildren()) {
totalHeight += child.prefHeight(-1) + child.getLayoutY();
}
resizeStage(totalHeight);
}
private void resizeStage(double height) {
// set height of stage to height
}
}
Код: Выделить всё
public class DynamicResizeApplication extends Application {
@Override
public void start(Stage stage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(DynamicResizeApplication.class.getResource("view/dynamic-resize-view.fxml"));
Scene scene = new Scene(fxmlLoader.load());
stage.setScene(scene);
stage.initStyle(StageStyle.UNDECORATED);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... x-elements