import javafx.application.Application; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableRow; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.util.Callback; public class TableSample extends Application { private static String E_NAME = "ename"; private void init(Stage primaryStage) { VBox root = new VBox(); root.getStylesheets().add("test.css"); primaryStage.setScene(new Scene(root)); TableColumn firstNameCol = new TableColumn(); firstNameCol.setText("First"); firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName")); TableColumn lastNameCol = new TableColumn(); lastNameCol.setText("Last"); lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName")); TableColumn emailCol = new TableColumn(); emailCol.setText("Email"); emailCol.setMinWidth(200); emailCol.setCellValueFactory(new PropertyValueFactory("email")); final TableView tableView = new TableView(); tableView.getColumns().addAll(firstNameCol, lastNameCol, emailCol); tableView.setRowFactory(new Callback, TableRow>() { @Override public TableRow call(TableView arg0) { return new TableRow() { @Override protected void updateItem(Person item, boolean empty) { super.updateItem(item, empty); if (empty || !item.firstName.get().startsWith("E")) { getStyleClass().remove(E_NAME); } else { getStyleClass().add(E_NAME); } } }; } }); addItems(tableView); addItems(tableView); Button r = new Button("Add items"); r.setOnAction(new EventHandler() { @Override public void handle(ActionEvent arg0) { addItems(tableView); // tableView.sort(); } }); root.getChildren().addAll(tableView, r); VBox.setVgrow(tableView, Priority.ALWAYS); } private static void addItems(TableView tableView) { tableView.getItems().addAll(new Person("Jacob", "Smith", "jacob.smith@example.com"), new Person("Isabella", "Johnson", "isabella.johnson@example.com"), new Person("Ethan", "Williams", "ethan.williams@example.com"), new Person("Emma", "Jones", "emma.jones@example.com"), new Person("Michael", "Brown", "michael.brown@example.com")); } public static class Person { private StringProperty firstName; private StringProperty lastName; private StringProperty email; private Person(String fName, String lName, String email) { this.firstName = new SimpleStringProperty(fName); this.lastName = new SimpleStringProperty(lName); this.email = new SimpleStringProperty(email); } public StringProperty firstNameProperty() { return firstName; } public StringProperty lastNameProperty() { return lastName; } public StringProperty emailProperty() { return email; } } @Override public void start(Stage primaryStage) throws Exception { init(primaryStage); primaryStage.show(); } public static void main(String[] args) { launch(args); } }