0
Wie können wir eine hbox passend zu seinem übergeordneten AnchorPane, wie wir es in FXML sceneBuilder tun.HBox: Fit zu übergeordnet AnchorPane Javafx, nicht mit FXML
AnchorPane root = new AnchorPane();
Scene scene = new Scene(root, 700, 500);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
//MenuBar
MenuBar menuBar=new MenuBar();
Menu file=new Menu("File");
MenuItem loadStudentData=new MenuItem("Load Student Data Ctrl+L");
MenuItem saveStudentData=new MenuItem("Save Student Data Ctrl+S");
MenuItem exit=new MenuItem("Exit Ctrl+X");
Menu help=new Menu("Help");
MenuItem about=new MenuItem("About");
file.getItems().add(loadStudentData);
file.getItems().add(saveStudentData);
file.getItems().add(exit);
help.getItems().add(about);
menuBar.getMenus().addAll(file);
menuBar.getMenus().addAll(help);
HBox hboxMenu=new HBox();
hboxMenu.getChildren().add(menuBar);
HBox.setHgrow(menuBar, Priority.ALWAYS);
root.getChildren().add(hboxMenu);
primaryStage.setScene(scene);
primaryStage.show();
I want menuBar to get auto resize when window is resized.