Issue
im working on a project and i need to populate a TableView with data from a database. in this same project i've worked with other TableView and i had no problem so far. but i already tried a lot of stuff, checked the solution to this: Javafx tableview not showing data in all columns and didnt work either, i already dont know what to do, hope you can help me, ill show you the code:
TableView column fill:
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));
}
My Exam 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);
}
}
my filling function with data from database (i already checked and the data is there, the problem is the tableview):
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);
}
Solution
Rename the getters and setters using camelCase.
This is a java standard:
public String getFoo()
{
return this.foo;
}
public void setFoo(String foo)
{
this.foo = foo;
}
Answered By - Renis1235