I assume it is possible to conditionally format JavaFX ComboBoxTableCell label according to following JavaFX 11 documentation items:
- ComboBoxTableCell class description:
By default, the
ComboBoxTableCellis rendered as aLabelwhen not being edited [...].
- Labeled class
setTextFillmethod description:
Sets the value of the property
textFill.
If my assumption is correct, I would like to know how to modify following SSCCE so that any ComboBoxTableCell label textFill property is set to following Paint values. Thank you!
Color.Redif its value is not valid
Color.Blueif its value is set for different rows.
public class PersonInRoom extends Application
{
private final ObservableList<Person> data = FXCollections.observableArrayList(
new Person("Jacob" , "Kitchen"),
new Person("Isabella", "Bedroom"),
new Person("Ethan" , "Attic"));
TableView<Person> table ;
public static void main(String[] args) {launch(args);}
@Override
public void start(Stage stage)
{
TableColumn nameCol = new TableColumn("Name");
nameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("name"));
TableColumn roomCol = new TableColumn("Room");
roomCol.setCellValueFactory(new PropertyValueFactory<Person, String>("room"));
roomCol.setCellFactory(ComboBoxTableCell.forTableColumn("Bathroom", "Bedroom", "Kitchen"));
roomCol.setOnEditCommit((EventHandler<CellEditEvent<Person, String>>) t -> t.getTableView().getItems().get(t.getTablePosition().getRow()).setRoom(t.getNewValue()));
table = new TableView<>();
table.setEditable(true);
table.setItems(data);
table.getColumns().addAll(nameCol, roomCol);
VBox vbox = new VBox();
vbox.getChildren().addAll(table);
Scene scene = new Scene(vbox);
stage.setScene(scene);
stage.show();
}
public static class Person
{
private final SimpleStringProperty name;
private final SimpleStringProperty room;
private Person(String name, String room)
{
this.name = new SimpleStringProperty(name);
this.room = new SimpleStringProperty(room);
}
public String getName() {return name.get();}
public String getRoom() {return room.get();}
public void setRoom(String r) {room.set(r);}
}
}

