在我的程序中,我尝试将一个填充了 CheckBox 的 HBox 输出到屏幕上。但是,当我运行该程序时,与其他复选框相比,CheckBox "A" 的间距要大得多。
这是我的代码:
private Scene assets (Stage primaryStage){
GridPane gp = new GridPane();
gp.setVgap(5);
gp.setPadding(new Insets(25, 25, 25, 25));
Text title = new Text("Assets");
title.setFont(Font.font("Arial", FontWeight.BOLD, 14));
gp.add(title, 0, 0);
Text description = new Text("Please select all assets you would like to include in your budget");
gp.add(description, 0, 1);
String [] optionsString = new String []{"A", "B", "C", "D", "E", "F"};
for (int i = 0; i < optionsString.length; i++) {
final int column = i;
final int row = i;
String option = optionsString[i];
CheckBox checkBox = new CheckBox(option);
HBox checkboxContainer = new HBox(checkBox);
checkboxContainer.setSpacing(20);
ChoiceBox<Integer> choice = new ChoiceBox<>();
Label label = new Label("How many " + optionsString[i] + " options do you have?");
choice.getItems().addAll(1, 2, 3, 4, 5);
HBox choiceContainer = new HBox(label, choice);
checkBox.selectedProperty().addListener((o, oldValue, newValue) -> {
if (newValue) {
gp.add(choiceContainer, 0, row + 4);
} else {
gp.getChildren().remove(choiceContainer);
}
});
gp.add(checkboxContainer, column, 3);
}
assets = new Scene (gp, 1280, 720);
return assets;
}
编辑:这是我在说什么的截图
拉莫斯之舞
GCT1015
相关分类