舞台显示之前的窗格的JavaFX getWidth

时间:2019-05-15 15:21:33

标签: java javafx

我有此代码:

public void start(Stage primaryStage){

    VBox mainPanel = new VBox();
    mainPanel.setStyle("-fx-background-color: rgba(255, 255, 255, 1);");
    mainPanel.setPadding(insetsPadding);
    mainPanel.setAlignment(Pos.TOP_LEFT);

    primaryStage.setScene(new Scene(mainPanel));

    //ACTIONS
    TitledPane collectPanel = getCollectPanel();
    TitledPane fulfillPanel = getFulfillPanel();
    TitledPane removeFulfillPanel = getRemoveFulfillPanel();

    HBox actionsPanel = new HBox();

    HBox.setMargin(collectPanel, insetsRight);
    HBox.setMargin(fulfillPanel, insetsRight);

    actionsPanel.getChildren().addAll(collectPanel, fulfillPanel, removeFulfillPanel);

    VBox.setMargin(actionsPanel, insetsBottom);

    mainPanel.getChildren().add(actionsPanel);

    //ORDERS LIST
    System.out.println(actionsPanel.getWidth()); // -> 0
    TitledPane ordersListPanel = getOrdersListPanel(actionsPanel.getWidth());

    mainPanel.getChildren().add(ordersListPanel);

    primaryStage.sizeToScene();
    primaryStage.centerOnScreen();
    primaryStage.show();

    System.out.println(actionsPanel.getWidth()); // -> 1310 << VALUE I NEED

}

这是窗口的外观:

因此,我想采用Pane(actionsPanel)的宽度来保存收集,实现和删除填充,并使用该宽度来创建具有相同宽度的TextArea

我的问题是我不知道如何使用actionsPanel的宽度。您可以在代码(注释)中看到,actionsPanel的宽度在primaryStage.show()之前为0。

如何获取/计算actionsPanel之前的primaryStage.show()的实际宽度

0 个答案:

没有答案