Мне нужно динамически получить ширину левой части моего JavaFX-BorderPane . Вот фрагмент кода, но оба метода, которые я использую, всегда возвращают 0, хотя левый компонент размещен в этот момент времени ...
double leftWidth = ((VBox) this.getLeft()).getWidth();
то же самое с:
double leftWidth = ((VBox) this.getLeft()).getLayoutBounds().getWidth();
Как это сделать правильно?
Здесь mcve:
public class BorderPaneExample extends Application {
@Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Left side of BorderPane");
BorderPane root = new BorderPane();
root.setLeft(btn);
Scene scene = new Scene(root, 640, 480);
primaryStage.setScene(scene);
primaryStage.show();
// ... later on retrieve the width of the left side:
System.out.println(root.getLeft().getLayoutBounds().getWidth());
}
public static void main(String[] args) {
launch(args);
}}