我接近这个吗?

时间:2016-03-24 11:13:54

标签: tableview javafx-8 fxml

JavaFX 8 - FXML - TableView - TableColumn 我有以下对象

CourseResult
    SimpleStringProperty CourseID
    SimpleStringProperty CourseName
    SimpleStringProperty Grade
    SimpleIntegerProperty Credits

ATableRow
    SimpleStringProperty StudentID
    SimpleStringProperty StudentName
    CourseResult[]  AResult  // Occurs 1 to 20.

在我的程序中

javafx.collections.ObservableList<ATableRow> TableData = javafx.collections.FXCollections.observableArrayList();

我从数据库填充此Observable列表,我能够在调试器中完美地看到所有值。 我创建了Tableview并添加了列。

    public void createTableForThisSemester(int thisSemester, int numberOfCourses, javafx.collections.ObservableList<AResultRow> TableRows) {

        TableView<AResultRow> thisTable = new TableView<>();

        TableColumn<AResultRow, String> tcolRollNo = new TableColumn<>("Roll Number");
        tcolRollNo.setEditable(false);
        tcolRollNo.setPrefWidth(120);

        TableColumn<AResultRow, String> tcolName = new TableColumn<>("Student Name");
        tcolName.setEditable(false);
        tcolName.setPrefWidth(350);

        tcolRollNo.setCellValueFactory(cellData -> cellData.getValue().StudentIDProperty());
        tcolName.setCellValueFactory(cellData -> cellData.getValue().StudentNameProperty());
        boolean xyz = thisTable.getColumns().addAll(tcolRollNo, tcolName);

 //       TableColumn[] courseColumn = new TableColumn[numberOfCourses];

        for (int courseNo = 0; courseNo < numberOfCourses; courseNo++) {
            String colName = getASemesterCourse(thisSemester, courseNo).getCourseID();
            TableColumn<AResultRow, String> thisColumn = new TableColumn<>(colName);
            thisColumn.setPrefWidth(80);
            thisColumn.setStyle("-fx-alignment: CENTER; font-weight:bold;");

thisColumn.setCellValueFactory(cellData -> cellData.getValue().courseGradeProperty(courseNo));

            boolean retVal = thisTable.getColumns().addAll(thisColumn);
        }
//        System.out.println("# of Rows in Table [" + thisSemester + "] = " + TableRows.size());

        thisTable.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
        thisTable.setItems(TableRows);

        ScrollPane thisScrollPane = new ScrollPane();
        thisScrollPane.setFitToWidth(true);
        thisScrollPane.setFitToHeight(true);
        thisScrollPane.setMinHeight((theDetails.getHeight() - 25));
        thisScrollPane.setMaxHeight((theDetails.getHeight() - 25));
        thisScrollPane.setMinWidth((theDetails.getWidth() - 25));
        thisScrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
        Tab thisTab = tabs.getTabs().get(thisSemester);
        thisTab.setContent(thisScrollPane);

        thisScrollPane.setContent(thisTable);
    }

Columns StudentID和Name完全填充。但结果没有填入

thisColumn.setCellValueFactory(cellData - &gt; cellData.getValue()。courseGradeProperty(courseNo));

我在Netbeans中看到上面显示的这个错误。 “从lambda表达式引用的局部变量必须是最终的或有效的最终结果。”

请记住,GRADE [courseNo]字段是一个字符串并填充。

如何在TABLE中显示此值。

我一直在尝试各种方法,比如将这个值存储在临时字符串......等等。

0 个答案:

没有答案