TableView 不显示任何值 Javafx 8
TableView not showing any value Javafx 8
我正在处理一个项目,我需要用数据库中的数据填充 TableView。在同一个项目中,我与其他 TableView 一起工作,到目前为止我没有遇到任何问题。但我已经尝试了很多东西,检查了解决方案:Javafx tableview not showing data in all columns 也没有用,我已经不知道该怎么做,希望你能帮助我,我给你看代码:
TableView 列填充:
private void fillColumns(){
TableColumn<Exam, String> column1 = new TableColumn<>("Estudio");
column1.setCellValueFactory(new PropertyValueFactory<>("estudio"));
TableColumn<Exam, String> column2 = new TableColumn<>("Doctor");
column2.setCellValueFactory(new PropertyValueFactory<>("doctor"));
TableColumn<Exam, String> column3 = new TableColumn<>("Fecha");
column3.setCellValueFactory(new PropertyValueFactory<>("fecha"));
TableColumn<Exam, String> column4 = new TableColumn<>("Descripcion");
column4.setCellValueFactory(new PropertyValueFactory<>("descripcion"));
TableColumn<Exam, String> column5 = new TableColumn<>("Precio");
column5.setCellValueFactory(new PropertyValueFactory<>("precio"));
TableColumn<Exam, String> column6 = new TableColumn<>("Paciente");
column6.setCellValueFactory(new PropertyValueFactory<>("paciente"));
//add columns
tvExam.getColumns().clear();
tvExam.getColumns().add(column1);
tvExam.getColumns().add(column2);
tvExam.getColumns().add(column3);
tvExam.getColumns().add(column4);
tvExam.getColumns().add(column5);
tvExam.getColumns().add(column6);
column1.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.2));
column2.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.3));
column3.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.1));
column4.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.2));
column5.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.1));
column6.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.1));
}
我的考试Class:
public class Exam {
protected SimpleStringProperty estudio = null;
protected SimpleStringProperty doctor = null;
protected SimpleStringProperty fecha = null;
protected SimpleStringProperty descripcion = null;
protected SimpleFloatProperty precio;
protected SimpleStringProperty paciente = null;
public Exam() {
}
public Exam(String estudio, String doctor, String fecha, String descripcion, float precio, String paciente){
this.estudio = new SimpleStringProperty(estudio);
this.descripcion = new SimpleStringProperty(descripcion);
this.doctor = new SimpleStringProperty(doctor);
this.fecha = new SimpleStringProperty(fecha);
this.precio = new SimpleFloatProperty(precio);
this.paciente = new SimpleStringProperty(paciente);
}
public String getpaciente() {
return paciente.get();
}
public void setpaciente(String paciente) {
this.paciente = new SimpleStringProperty(paciente);
}
public String getestudio() {
return estudio.get();
}
public void setestudio(String estudio) {
this.estudio = new SimpleStringProperty(estudio);
}
public String getdoctor() {
return doctor.get();
}
public void setdoctor(String doctor) {
this.doctor = new SimpleStringProperty(doctor);
}
public String getfecha() {
return fecha.get();
}
public void setfecha(String fecha) {
this.fecha = new SimpleStringProperty(fecha);
}
public String getdescripcion() {
return descripcion.get();
}
public void setdescripcion(String descripcion) {
this.descripcion = new SimpleStringProperty(descripcion);
}
public float getprecio() {
return precio.get();
}
public void setprecio(float precio) {
this.precio = new SimpleFloatProperty(precio);
}
}
我用数据库中的数据填充函数(我已经检查过并且数据在那里,问题是表格视图):
while (resultSet.next()) {
Exam nuevo = new Exam();
nuevo.setdoctor(resultSet.getString("fecha"));
nuevo.setestudio(resultSet.getString("estudio"));
nuevo.setpaciente(resultSet.getString("paciente"));
nuevo.setdescripcion(resultSet.getString("descripcion"));
nuevo.setfecha(resultSet.getString("fecha"));
nuevo.setprecio(resultSet.getFloat("precio"));
tvExam.getItems().add(fila);
}
使用驼峰命名重命名 getter 和 setter。
这是 java 标准:
public String getFoo()
{
return this.foo;
}
public void setFoo(String foo)
{
this.foo = foo;
}
我正在处理一个项目,我需要用数据库中的数据填充 TableView。在同一个项目中,我与其他 TableView 一起工作,到目前为止我没有遇到任何问题。但我已经尝试了很多东西,检查了解决方案:Javafx tableview not showing data in all columns 也没有用,我已经不知道该怎么做,希望你能帮助我,我给你看代码:
TableView 列填充:
private void fillColumns(){
TableColumn<Exam, String> column1 = new TableColumn<>("Estudio");
column1.setCellValueFactory(new PropertyValueFactory<>("estudio"));
TableColumn<Exam, String> column2 = new TableColumn<>("Doctor");
column2.setCellValueFactory(new PropertyValueFactory<>("doctor"));
TableColumn<Exam, String> column3 = new TableColumn<>("Fecha");
column3.setCellValueFactory(new PropertyValueFactory<>("fecha"));
TableColumn<Exam, String> column4 = new TableColumn<>("Descripcion");
column4.setCellValueFactory(new PropertyValueFactory<>("descripcion"));
TableColumn<Exam, String> column5 = new TableColumn<>("Precio");
column5.setCellValueFactory(new PropertyValueFactory<>("precio"));
TableColumn<Exam, String> column6 = new TableColumn<>("Paciente");
column6.setCellValueFactory(new PropertyValueFactory<>("paciente"));
//add columns
tvExam.getColumns().clear();
tvExam.getColumns().add(column1);
tvExam.getColumns().add(column2);
tvExam.getColumns().add(column3);
tvExam.getColumns().add(column4);
tvExam.getColumns().add(column5);
tvExam.getColumns().add(column6);
column1.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.2));
column2.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.3));
column3.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.1));
column4.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.2));
column5.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.1));
column6.prefWidthProperty().bind(tvExam.widthProperty().multiply(0.1));
}
我的考试Class:
public class Exam {
protected SimpleStringProperty estudio = null;
protected SimpleStringProperty doctor = null;
protected SimpleStringProperty fecha = null;
protected SimpleStringProperty descripcion = null;
protected SimpleFloatProperty precio;
protected SimpleStringProperty paciente = null;
public Exam() {
}
public Exam(String estudio, String doctor, String fecha, String descripcion, float precio, String paciente){
this.estudio = new SimpleStringProperty(estudio);
this.descripcion = new SimpleStringProperty(descripcion);
this.doctor = new SimpleStringProperty(doctor);
this.fecha = new SimpleStringProperty(fecha);
this.precio = new SimpleFloatProperty(precio);
this.paciente = new SimpleStringProperty(paciente);
}
public String getpaciente() {
return paciente.get();
}
public void setpaciente(String paciente) {
this.paciente = new SimpleStringProperty(paciente);
}
public String getestudio() {
return estudio.get();
}
public void setestudio(String estudio) {
this.estudio = new SimpleStringProperty(estudio);
}
public String getdoctor() {
return doctor.get();
}
public void setdoctor(String doctor) {
this.doctor = new SimpleStringProperty(doctor);
}
public String getfecha() {
return fecha.get();
}
public void setfecha(String fecha) {
this.fecha = new SimpleStringProperty(fecha);
}
public String getdescripcion() {
return descripcion.get();
}
public void setdescripcion(String descripcion) {
this.descripcion = new SimpleStringProperty(descripcion);
}
public float getprecio() {
return precio.get();
}
public void setprecio(float precio) {
this.precio = new SimpleFloatProperty(precio);
}
}
我用数据库中的数据填充函数(我已经检查过并且数据在那里,问题是表格视图):
while (resultSet.next()) {
Exam nuevo = new Exam();
nuevo.setdoctor(resultSet.getString("fecha"));
nuevo.setestudio(resultSet.getString("estudio"));
nuevo.setpaciente(resultSet.getString("paciente"));
nuevo.setdescripcion(resultSet.getString("descripcion"));
nuevo.setfecha(resultSet.getString("fecha"));
nuevo.setprecio(resultSet.getFloat("precio"));
tvExam.getItems().add(fila);
}
使用驼峰命名重命名 getter 和 setter。
这是 java 标准:
public String getFoo()
{
return this.foo;
}
public void setFoo(String foo)
{
this.foo = foo;
}