I have a simple TableView with two Columns(Id, Valid).
The code of the table looks like this:
private TableView<List<Object>> createTable()
{
TableView<List<Object>> table = new TableView<>();
TableColumn<List<Object>, String> idCol = new TableColumn<>("ID");
idCol.setCellValueFactory(new Callback<CellDataFeatures<List<Object>, String>, ObservableValue<String>>()
{
public ObservableValue<String> call(CellDataFeatures<List<Object>, String> param)
{
return new SimpleStringProperty(param.getValue().get(0).toString());
}
});
TableColumn<List<Object>, String> validCol = new TableColumn<>("Valid");
validCol.setCellValueFactory(new Callback<CellDataFeatures<List<Object>, String>, ObservableValue<String>>()
{
public ObservableValue<String> call(CellDataFeatures<List<Object>, String> param)
{
return new SimpleStringProperty(param.getValue().get(1).toString());
}
});
table.getColumns().addAll(idCol, validCol);
List<Object> firstRow = new ArrayList<Object>();
firstRow.add(1);
firstRow.add(0);
List<Object> secondRow = new ArrayList<Object>();
secondRow.add(2);
secondRow.add(1);
table.getItems().addAll(firstRow, secondRow);
return table;
}
The background of valid rows should turn green, and the not valid rows red. I realised that by set a rowfactory:
table.setRowFactory(new Callback<TableView<List<Object>>, TableRow<List<Object>>>()
{
@Override
public TableRow<List<Object>> call(TableView<List<Object>> param)
{
return new TableRow<List<Object>>()
{
@Override
protected void updateItem(List<Object> item, boolean empty)
{
super.updateItem(item, empty);
if (!empty)
{
int valid = Integer.parseInt(item.get(1).toString());
if (valid == 1)
setBackground(MyCustomBackGround.VALID);
else if (valid == 0)
setBackground(MyCustomBackGround.NOT_VALID);
else
setBackground(MyCustomBackGround.WHITE);
}
}
};
}
});
This seems to work okay. But now I want to change the color of my selection. Lets say I want to darken the set color.
How can I realise that?