I have a TableView with several columns, one is a ComboBox column and 5 other are CheckBox columns. When I try to popullate the table some of the CheckBox cells should have the tick mark and the column with the ComboBox should show only the text of the ObservableList (only one letter in this case) but it shows what seems to be the value in memory stored. I add code and images of what it looks like and what I wnat it to look like.
private final ObservableList<Treatment> data = FXCollections.observableArrayList(
new Treatment("A", true,true,true,true, false),
new Treatment("B", true,true,true,true, false),
new Treatment("C", true,true,true,true, false),
new Treatment("D", true,true,true,true, false),
new Treatment("E", true,true,true,true, false)
);
Now I create my columns and set the CellFactory as a ComboBox or a CheckBox.
instrumental.setCellValueFactory(new PropertyValueFactory<Treatment,String>("treatment"));
instrumental.setCellFactory(ComboBoxTableCell.forTableColumn("A","B", "C", "D"));
instrumental.setOnEditCommit(
new EventHandler<CellEditEvent<Treatment, String>>() {
@Override
public void handle(CellEditEvent<Treatment, String> t) {
((Treatment) t.getTableView().getItems().get(
t.getTablePosition().getRow())
).setTratamiento(t.getNewValue());
}
}
);
c1.setCellValueFactory(new PropertyValueFactory<Treatment,Boolean>("c1"));
c1.setCellFactory(column -> new CheckBoxTableCell());
c2.setCellValueFactory(new PropertyValueFactory<Treatment,Boolean>("c2"));
c2.setCellFactory(column -> new CheckBoxTableCell());
c3.setCellValueFactory(new PropertyValueFactory<Treatment,Boolean>("c3"));
c3.setCellFactory(column -> new CheckBoxTableCell());
c4.setCellFactory(column -> new CheckBoxTableCell());
c4.setCellValueFactory(new PropertyValueFactory<Treatment,Boolean>("c4"));
c5.setCellValueFactory(new PropertyValueFactory<Treatment,Boolean>("c5"));
c5.setCellFactory(column -> new CheckBoxTableCell());
Here is where I add my observable list to the table
table.setItems(data);
This is the Treatment class
public class Treatment {
public SimpleStringProperty Treatment ;
public BooleanProperty c1;
public SimpleBooleanProperty c2;
public SimpleBooleanProperty c3;
public SimpleBooleanProperty c4;
public SimpleBooleanProperty c5;
public Treatment(String treatmentc, boolean c1c, boolean c2c, boolean c3c, boolean c4c, boolean c5c) {
treatment= new SimpleStringProperty (treatmentc);
c1 = new SimpleBooleanProperty (c1c);
c2 = new SimpleBooleanProperty (c2c);
c3 = new SimpleBooleanProperty (c3c);
c4 = new SimpleBooleanProperty (c4c);
c4 = new SimpleBooleanProperty (c5c);
}
public StringProperty getTreatment() {
return treatment;
}
public void setTreatment(String treatment) {
this.treatment.set(treatmentc);
}
public BooleanProperty getC1() {
return c1;
}
public void setC1(Boolean c1) {
this.c1.set(c1);
}
public BooleanProperty getC2() {
return c2;
}
public void setC2(SimpleBooleanProperty c2) {
this.c2 = c2;
}
public BooleanProperty getC3() {
return c3;
}
public void setC3(SimpleBooleanProperty c3) {
this.c3 = c3;
}
public BooleanProperty getC4() {
return c4;
}
public void setC4(SimpleBooleanProperty c4) {
this.c4 = c4;
}
public BooleanProperty getC5() {
return c5;
}
public void setC5(SimpleBooleanProperty c5) {
this.c5 = c5;
}
}
This is an image of what it looks like originally
This is not a duplicate. The problem isn't about getting the values, it's about filling the TableView. If I don't use a CellFactory, the table popullates with the String values of the ObservableList ("true", "false" etc...)