TitledPane循环只有最后一个有内容

时间:2015-11-24 12:37:53

标签: java javafx controller fxml gridpane

我正在以编程方式构建我的fxml

现在我在手风琴中添加了一个标题窗格,在那些标题窗格中,我setContent添加了一个在循环中定义的网格窗格。

结果屏幕显示我已添加的所有标题栏。它显示了我设置的标题栏的标题。但它只显示了我添加的最后一个标题栏的内容。

我不明白为什么,因为我所制作的arraylist中仍然存在对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);
}
...
}

Example

0 个答案:

没有答案