package helloworld; import javafx.application.Application; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.value.ObservableValue; import javafx.stage.Stage; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.util.Callback; import javafx.scene.control.*; import javafx.scene.control.TableColumn.CellDataFeatures; public class TableRowCSS extends Application { public void start(Stage stage) { ObservableList numbers = FXCollections. observableArrayList(); for (int i = 0; i < 100; i++) numbers.add(i); System.out.println(numbers); TableView table = new TableView(); TableColumn number = new TableColumn(); number.setText("Number"); number.setPrefWidth(100); number.setCellValueFactory(new Callback, ObservableValue>() { public ObservableValue call(CellDataFeatures cdf) { return new ReadOnlyObjectWrapper(cdf.getValue()); } }); number.setCellFactory(new Callback, TableCell>() { public TableCell call(TableColumn column) { return new TableCell() { @Override protected void updateItem(Integer n, boolean empty) { super.updateItem(n, empty); if (empty) { setText(null); } else { setText(n.toString()); if (n > 50) { if (! getStyleClass().contains("my-class")) { getStyleClass().add("my-class"); } } else { getStyleClass().remove("my-class"); } } System.out.println("styleclass for index: " + getIndex() + " (where n = " + n + "): " + getStyleClass()); } }; } }); table.getColumns().add(number); table.setItems(numbers); Scene scene = new Scene(table, 800, 600); scene.getStylesheets().add(getClass().getResource("TableRowCSS.css").toExternalForm()); stage.setScene(scene); stage.show(); } public static void main(String[] args) { Application.launch(); } }