For Button this works. For GridPane doesn't works: gridPane.applyCss(); gridPane.layout(); double width = gridPane.getWidth(); double height = gridPane.getHeight(); System.out.println("width=" + width + ", height=" + height); --- exec-maven-plugin:1.5.0:exec (default-cli) --- width=0.0, height=0.0
On Thu, Aug 23, 2018 at 6:56 PM Shakir Gusaroff <shakir.gusar...@gmail.com> wrote: > . In javafx 8 you can find the width and height of the node before the > Stage has been shown. Use applyCss() and layout(). > > > > > > > @Override > > public void start(Stage stage) throws Exception { > > > > Group root = new Group(); > > Scene scene = new Scene(root); > > > > Button button = new Button("Hello World"); > > root.getChildren().add(button); > > > > root.applyCss(); > > root.layout(); > > > > double width = button.getWidth(); > > double height = button.getHeight(); > > > > System.out.println(width + ", " + height); > > > > stage.setScene(scene); > > stage.show(); > > } > > > On Thu, Aug 23, 2018 at 10:35 AM Miroslav Nachev < > mnachev.nscenter...@gmail.com> wrote: > >> Hi, >> >> Is there any standard way to calculate the preferred size for Scene, >> Node/Pane and Stage/Window? >> I want once a form/pane is visualized, it cannot be minimized to a certain >> size. Since I did not find such a built-in opportunity, at the moment I am >> doing the following: >> >> Scene scene = new Scene(gridPane); >> primaryStage.setScene(scene); >> primaryStage.sizeToScene(); >> >> primaryStage.show(); >> primaryStage.setMinWidth(primaryStage.getWidth() + 1); >> primaryStage.setMinHeight(primaryStage.getHeight() + 1); >> primaryStage.setWidth(640); >> primaryStage.setHeight(480); >> primaryStage.show(); >> >> The first call to primaryStage.show() (in orange) I do to calculate the >> minimum panel size (Scene/GridPane), then set that size as minimum on >> primaryStage, and finally set the size I want and visualize the panel >> again. >> >> The unpleasant side effect is, that the panel is no longer at the center >> of >> the screen. >> >> Any ideas? >> >> >> Regards, >> Miro. >> >