包含 DatePickers 时,GridPane 的大小似乎不正确。任何人都知道发生了什么或潜在的解决方法?我已经尝试了许多其他节点(CheckBox、ChoiceBox 等),而 DatePicker 似乎是唯一导致这种行为的节点。想法?
编辑:尽管也像 DatePicker 那样扩展了 ComboBoxBase,但 ColorPicker 和 ComboBox 似乎都很好。
@Override
public void start(Stage primaryStage) {
HBox goodBox = new HBox();
goodBox.setStyle("-fx-border-color: green");
goodBox.setPadding(new Insets(5));
GridPane goodGrid = new GridPane();
goodGrid.setHgap(5);
goodGrid.setVgap(5);
goodGrid.addColumn(0, new Label("Good 1:"), new Label("Good 2:"));
goodGrid.addColumn(1, new TextField(), new TextField());
goodBox.getChildren().add(goodGrid);
HBox badBox = new HBox();
badBox.setStyle("-fx-border-color: red");
badBox.setPadding(new Insets(5));
GridPane badGrid = new GridPane();
badGrid.setHgap(5);
badGrid.setVgap(5);
badGrid.addColumn(0, new Label("Bad 2:"), new Label("Bad 2:"));
badGrid.addColumn(1, new DatePicker(), new DatePicker());
badBox.getChildren().add(badGrid);
VBox root = new VBox(5);
root.setAlignment(Pos.TOP_LEFT);
root.setPadding(new Insets(5));
root.getChildren().addAll(goodBox, badBox);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}