I try to create a tableview with a different content for a combobox for each row. The user could add an entry to the tableview per button and the object of this entry define the content of the combobox (ObservableList will be changed in background, means it will be filled with new items after clicking a button). I successfully created a combobox for each row, but if I change the items, the content of every combobox in the tableview changes.
TableColumn<Filterparameter, String> kenntnisgradComboBoxColumn = new TableColumn<Filterparameter, String>("Ausprägung");
kenntnisgradComboBoxColumn.setCellValueFactory(new PropertyValueFactory<Filterparameter, String>(""));
Callback<TableColumn<Filterparameter, String>, TableCell<Filterparameter, String>> cellFactoryKenntnisgradComboBoxColumn = new Callback<TableColumn<Filterparameter, String>, TableCell<Filterparameter, String>>()
{
@Override
public TableCell<Filterparameter, String> call(final TableColumn<Filterparameter, String> param)
{
final TableCell<Filterparameter, String> cell = new TableCell<Filterparameter, String>()
{
// Display combobox if the row is not empty
@Override
public void updateItem(String item, boolean empty)
{
super.updateItem(item, empty);
if (empty)
{
setGraphic(null);
}
else
{
tableViewkennntisgradComboBox = new ComboBox<Kenntnisgrad>();
// Here content of every combobox changes instead of only changing the combobox of selected row
tableViewkennntisgradComboBox.setItems(selectedFilterParameter.getKenntnisgradAuswahl());
tableViewkennntisgradComboBox.setPadding(new Insets(-1, 0, -1, 0));
tableViewkennntisgradComboBox.setMinWidth(kenntnisgradComboBoxColumn.getWidth() - 6);
tableViewkennntisgradComboBox.setPrefWidth(kenntnisgradComboBoxColumn.getWidth() - 6);
tableViewkennntisgradComboBox.setMaxWidth(kenntnisgradComboBoxColumn.getWidth() - 6);
setGraphic(tableViewkennntisgradComboBox);
}
}
};
return cell;
}
};
kenntnisgradComboBoxColumn.setCellFactory(cellFactoryKenntnisgradComboBoxColumn);
Try to visualize the tableview for better understanding:
| TXT | COMBOBOX |
| Text1 | [ContentList1 >] |
| Text2 | [ContentList2 >] |
| ........ | [........................] |
Many thanks in advance!