import javafx.application.Application; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class TableViewTest extends Application { private void init(Stage primaryStage) { VBox root = new VBox(2); primaryStage.setScene(new Scene(root, 300, 300)); final ObservableList data = FXCollections.observableArrayList( new Person("Jacob", "Smith", "jacob.smith@example.com"), new TableViewTest.Person("Isabella", "Johnson", "isabella.johnson@example.com"), new TableViewTest.Person("Ethan", "Williams", "ethan.williams@example.com"), new TableViewTest.Person("Emma", "Jones", "emma.jones@example.com"), new TableViewTest.Person("Michael", "Brown", "michael.brown@example.com"), new TableViewTest.Person("Jacob", "Smith", "jacob.smith@example.com"), new TableViewTest.Person("Isabella", "Johnson", "isabella.johnson@example.com"), new TableViewTest.Person("Ethan", "Williams", "ethan.williams@example.com"), new TableViewTest.Person("Emma", "Jones", "emma.jones@example.com"), new TableViewTest.Person("Michael", "Brown", "michael.brown@example.com"), new TableViewTest.Person("Jacob", "Smith", "jacob.smith@example.com" ), new TableViewTest.Person("Isabella", "Johnson", "isabella.johnson@example.com" ), new TableViewTest.Person("Ethan", "Williams", "ethan.williams@example.com" ), new TableViewTest.Person("Emma", "Jones", "emma.jones@example.com" ), new TableViewTest.Person("Michael", "Brown", "michael.brown@example.com" )); 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.setCellValueFactory(new PropertyValueFactory("email")); TableView tableView = new TableView(); tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); tableView.getSelectionModel().setCellSelectionEnabled(true); tableView.setItems(data); tableView.getColumns().clear(); tableView.getColumns().addAll(firstNameCol, lastNameCol, emailCol); root.getChildren().addAll(tableView); } 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.setTitle("Table Test " + System.getProperty("javafx.runtime.version")); primaryStage.show(); } public static void main(String[] args) { launch(args); } }