package tableview.memtest; import java.util.List; import javafx.application.Application; import javafx.application.Platform; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TableColumn.CellDataFeatures; import javafx.stage.Stage; import javafx.util.Callback; /** * @created 27/03/2013 */ public class CellThrasher extends Application { private final List persons = FXCollections.observableArrayList( new Person("Jacob", "Smith\nSmith\nSmith", "jacob.smithexample.com"), new Person("Isabella", "Johnson", "isabella.johnsonexample.com" ), new Person("Ethan", "Williams", "ethan.williamsexample.com" ), new Person("Emma", "Jones", "emma.jonesexample.com" ), new Person("Michael", "Brown", "michael.brownexample.com"), new Person("Olivia", "Davis", "olivia.davisexample.com" ), new Person("Alexander", "Miller", "alexander.millerexample.com"), new Person("Sophia", "Wilson", "sophia.wilsonexample.com" ), new Person("William", "Moore", "william.mooreexample.com"), new Person("Ava", "Taylor", "ava.taylorexample.com" ), new Person("Joshua", "Anderson", "joshua.andersonexample.com" ), new Person("Emily", "Thomas", "emily.thomasexample.com" ), new Person("Daniel", "Jackson", "daniel.jacksonexample.com" ), new Person("Madison", "White", "madison.whiteexample.com" ), new Person("Jayden", "Harris", "jayden.harrisexample.com" ), new Person("Abigail", "Martin", "abigail.martinexample.com" ), new Person("Noah", "Thompson", "noah.thompsonexample.com" ), new Person("Chloe", "Garcia", "chloe.garciaexample.com" ), new Person("Anthony", "Martinez", "anthony.martinezexample.com" ), new Person("Mia", "Robinson", "mia.robinsonexample.com" ), new Person("Jacob", "Smith" ), new Person("Isabella", "Johnson" ), new Person("Ethan", "Williams" ), new Person("Emma", "Jones" ), new Person("Michael", "Brown" ), new Person("Olivia", "Davis" ), new Person("Alexander", "Miller" ), new Person("Sophia", "Wilson" ), new Person("William", "Moore" ), new Person("Ava", "Taylor" ), new Person("Joshua", "Anderson" ), new Person("Emily", "Thomas" ), new Person("Daniel", "Jackson" ), new Person("Madison", "White" ), new Person("Jayden", "Harris" ), new Person("Abigail", "Martin" ), new Person("Noah", "Thompson" ), new Person("Chloe", "Garcia" ), new Person("Anthony", "Martinez" ), new Person("Mia", "Robinson" ) ); /** * @param args */ public static void main(String[] args) { launch(); } public void init(Stage primaryStage) { Group root = new Group(); primaryStage.setScene(new Scene(root)); final ObservableList data = FXCollections.observableArrayList(); final TableColumn firstNameCol = new TableColumn(); firstNameCol.setText("First"); firstNameCol.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures param) { return param.getValue().firstNameProperty(); } }); final TableColumn lastNameCol = new TableColumn(); lastNameCol.setText("Last"); lastNameCol.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures param) { return param.getValue().lastNameProperty(); } }); final TableColumn emailCol = new TableColumn(); emailCol.setText("Email"); emailCol.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures param) { return param.getValue().emailProperty(); } }); final TableView tableView = new TableView(); tableView.setItems(data); tableView.getColumns().addAll(firstNameCol, lastNameCol, emailCol); root.getChildren().add(tableView); Thread thread = new Thread(new Runnable() { @Override public void run() { while (true) { Platform.runLater(new Runnable() { @Override public void run() { tableView.getColumns().clear(); data.clear(); data.addAll(persons); tableView.getColumns().addAll(firstNameCol, lastNameCol, emailCol); } }); try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } } }); thread.start(); } public static class Person { private StringProperty firstName; private StringProperty lastName; private StringProperty email; private Person(String fName, String lName) { this(fName, lName, null); } 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(); } }