我正在以fxml
编程方式构建我的。
现在,我在手风琴中添加了一个标题窗格,在这些标题窗格中,我必须setContent
添加一个在循环中定义的网格窗格。
结果屏幕显示了我添加的所有标题窗格。它显示了我设置的标题窗格的标题。但它只显示我添加的最后一个标题窗格的内容。
我不明白为什么,因为对 titledpane 的引用仍然存在于我制作的数组列表中,并且据我所知,我设置的内容(节点)保存在那里。看起来行和列约束对所有实例都有效,我认为这意味着已经为每个 TitledPane 找到了网格,但除了最后一个之外的每个都没有内容。
Public class FXMLController Implements Initializable {
@FXML private VBox vboxDrills;
//NonFXML
private ArrayList<TitledPane> lsttpDrillList;
private Accordion accDrill;
public void initLayout(ArrayList<Drill> drills){
accDrill = new Accordion();
lsttpDrillList = new ArrayList<>();
TitledPane tpDrill; //AP = AccordionPane
GridPane gpTopDrill;
Accordion accDrillStep;
GridPane gpBottomDrill;
//gpTopDrill
ColumnConstraints cc1gpTopDrill = new ColumnConstraints();
cc1gpTopDrill.setHgrow(Priority.SOMETIMES);
cc1gpTopDrill.setMaxWidth(Double.NEGATIVE_INFINITY);
cc1gpTopDrill.setMinWidth(10.0);
cc1gpTopDrill.setPrefWidth(200.0);
ColumnConstraints cc2gpTopDrill = new ColumnConstraints();
cc2gpTopDrill.setHgrow(Priority.SOMETIMES);
cc2gpTopDrill.setMaxWidth(Double.NEGATIVE_INFINITY);
cc2gpTopDrill.setMinWidth(10.0);
cc2gpTopDrill.setPrefWidth(400.0);
RowConstraints rc1gpTopDrill = new RowConstraints();
rc1gpTopDrill.setMaxHeight(Double.NEGATIVE_INFINITY);
rc1gpTopDrill.setMinHeight(Double.NEGATIVE_INFINITY);
rc1gpTopDrill.setPrefHeight(35.0);
rc1gpTopDrill.setVgrow(Priority.SOMETIMES);
Label lblDrillID = new Label();
lblDrillID.minHeight(Double.NEGATIVE_INFINITY);
lblDrillID.minWidth(Double.NEGATIVE_INFINITY);
lblDrillID.setText("Drill ID:");
Label lblActualID = new Label();
lblActualID.minHeight(Double.NEGATIVE_INFINITY);
lblActualID.minWidth(Double.NEGATIVE_INFINITY);
Label lblDrillTitle = new Label();
lblDrillTitle.setText("Drill Title:");
TextField txtDrillTitleEdit = new TextField();
//end gpTopDrill
for(int i=0; i<drills.size(); i++){
//new instance and title
Drill drill = drills.get(i);
tpDrill = new TitledPane();
if(!drill.getTitle().isEmpty()){
tpDrill.setText(drill.getTitle());
}else{
tpDrill.setText("Drill" + drill.getID());
}
tpDrill.setId("drillPane" + (i));
//gpTopDrill
lblActualID.setText(Integer.toString(drill.getID()));
txtDrillTitleEdit.setId("drillTitleEdit" + (i));
txtDrillTitleEdit.setText(drill.getTitle());
GridPane.setConstraints(lblDrillID, 0, 0);
GridPane.setConstraints(lblActualID, 1, 0);
GridPane.setConstraints(lblDrillTitle, 0, 1);
GridPane.setConstraints(txtDrillTitleEdit, 1, 1);
gpTopDrill = new GridPane();
gpTopDrill.getColumnConstraints().addAll(cc1gpTopDrill, cc2gpTopDrill);
gpTopDrill.getRowConstraints().addAll(rc1gpTopDrill, rc1gpTopDrill);
gpTopDrill.getChildren().addAll(lblDrillID, lblActualID, lblDrillTitle, txtDrillTitleEdit);
//end gpTopDrill
//accDrillStep
//end accDrillStep
//gpBottomDrill
//end gpBottomDrill
//put VBox in drillpane
tpDrill.setContent(gpTopDrill);
lsttpDrillList.add(tpDrill);
}
accDrill.getPanes().setAll(lsttpDrillList);
accDrill.layoutXProperty().set(8.0);
accDrill.layoutYProperty().set(7.0);
accDrill.setExpandedPane(lsttpDrillList.get(0));
vboxDrills.getChildren().add(0, accDrill);
}
...
}