我有此代码:
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()
的实际宽度