Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javafx中填充表格视图_Java_User Interface_Javafx_Tableview - Fatal编程技术网

在javafx中填充表格视图

在javafx中填充表格视图,java,user-interface,javafx,tableview,Java,User Interface,Javafx,Tableview,我有一个javafx中的tableview,我想用对象类型填充它。我的想法是,在我的课程中,我有一个复合主键,它是一个不同的课程ID。我想在tableview的一列中添加CourseId类中存在的courseno,但我不知道如何获取它 我的课程班: package com.licenta.ascourses.ui.model; import java.io.Serializable; public class Course implements Serializable { pri

我有一个javafx中的tableview,我想用对象类型填充它。我的想法是,在我的课程中,我有一个复合主键,它是一个不同的课程ID。我想在tableview的一列中添加CourseId类中存在的courseno,但我不知道如何获取它

我的课程班:

package com.licenta.ascourses.ui.model;

import java.io.Serializable;

public class Course implements Serializable {

    private CourseId idCourse = new CourseId();
    private int year;
    private int semester;
    private String discipline;
    private String professor;

    public Course() {

    }

    public Course(CourseId idCourse, int year, int semester) {
        super();
        this.idCourse = idCourse;
        this.year = year;
        this.semester = semester;
    }

    public Course(CourseId idCourse, int year, int semester, String discipline, String professor) {
        this.idCourse=idCourse;
        this.year = year;
        this.semester = semester;
        this.discipline = discipline;
        this.professor = professor;
    }

    public CourseId getIdCourse() {
        return idCourse;
    }

    public void setIdCourse(CourseId idCourse) {
        this.idCourse = idCourse;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }

    public String getDiscipline() {
        return discipline;
    }

    public void setDiscipline(String discipline) {
        this.discipline = discipline;
    }

    public String getProfessor() {
        return professor;
    }

    public void setProfessor(String professor) {
        this.professor = professor;
    }



}
我的班级:

package com.licenta.ascourses.ui.model;

import java.io.Serializable;



public class CourseId implements Serializable {

    private int idDiscipline;
    private int idProfessor;
    private int courseNo;

    public CourseId()   {

    }

    public CourseId(int idDiscipline, int idProfessor, int courseNo) {
        super();
        this.idDiscipline = idDiscipline;
        this.idProfessor = idProfessor;
        this.courseNo = courseNo;
    }

    public int getIdDiscipline() {
        return idDiscipline;
    }

    public void setIdDiscipline(int idDiscipline) {
        this.idDiscipline = idDiscipline;
    }

    public int getIdProfessor() {
        return idProfessor;
    }

    public void setIdProfessor(int idProfessor) {
        this.idProfessor = idProfessor;
    }

    public int getCourseNo() {
        return courseNo;
    }

    public void setCourseNo(int courseNo) {
        this.courseNo = courseNo;
    }

    public boolean equals(Object o) {

        return true;
    }

    public int hashCode() {

        return 1;
    }

}

columnNumarCurs.setCellValueFactory(new PropertyValueFactory<Course, Integer>(""));
        columnAn.setCellValueFactory(new PropertyValueFactory<Course, Integer>("year"));
        columnSemestru.setCellValueFactory(new PropertyValueFactory<Course, Integer>("semester"));
        columnDisciplina.setCellValueFactory(new PropertyValueFactory<Course, String>("discipline"));
        columnProfesor.setCellValueFactory(new PropertyValueFactory<Course, String>("professor"));
该方法需要回调:即将对象映射到包含要显示的值的ObservalEvalue的函数。由于您拥有的值是int,并且假设ColumnUMarcurs是TableColumn,因此适当的ObservalEvalue类型是IntegerProperty。因此,您可以:

columnNumarCurs.setCellValueFactory(
    cellData -> new SimpleIntegerProperty(cellData.getValue().getIdCourse().getCourseNo()));