package main; import javafx.application.Application; import javafx.beans.property.StringProperty; 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.layout.BorderPane; import javafx.stage.Stage; /** * * @author Jonathan */ public class Main extends Application { public static void main(String... arg) { launch(arg); } public static class Person { private StringProperty firstName; private StringProperty lastName; private StringProperty email; private final String country = "New Zealand"; private Person(String fName, String lName) { this(fName, lName, null); } private Person(String fName, String lName, String email) { this.firstName = new StringProperty(fName); this.lastName = new StringProperty(lName); this.email = new StringProperty(email); } public String getFirstName() { return firstName.get(); } public void setFirstName(String firstName) { this.firstName.set(firstName); } public StringProperty firstNameProperty() { return firstName; } public String getLastName() { return lastName.get(); } public void setLastName(String lastName) { this.lastName.set(lastName); } public StringProperty lastNameProperty() { return lastName; } public String getEmail() { return email.get(); } public void setEmail(String email) { this.email.set(email); } public StringProperty emailProperty() { return email; } public String getCountry() { return country; } public String toString() { return "Person [ " + getFirstName() + " " + getLastName()/* + ", " + getEmail()*/ + " ]"; } } public void start(Stage primaryStage) throws Exception { Group rootGroup = new Group(); Scene scene = new Scene(rootGroup, 800, 600); primaryStage.setScene(scene); ObservableList testItems = FXCollections.observableArrayList(); testItems.addAll( // // sources for names: // // http://www.ssa.gov/OACT/babynames/ // // http://names.mongabay.com/most_common_surnames.htm // new Person("Jacob", "Smith", "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" ) ); TableView table = new TableView(); table.setItems(testItems); TableColumn testColumn = new TableColumn("Width"); // testColumn.setResizable(true); testColumn.setProperty("firstName"); // testColumn.setMaxWidth(100); TableColumn testColumn2 = new TableColumn("Height"); // testColumn2.setResizable(true); testColumn2.setProperty("lastName"); testColumn2.setMinWidth(100); table.getColumns().addAll(testColumn, testColumn2); table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); BorderPane mainPane = new BorderPane(); mainPane.setCenter(table); scene.setRoot(mainPane); primaryStage.centerOnScreen(); primaryStage.setVisible(true); } }