/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ import javafx.application.Application; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.stage.Stage; /** * * @author Alexander Kouznetsov */ public class TableViewCreateTest extends Application { @Override public void start(Stage stage) throws Exception { TableView table = new TableView(); Person person = new Person(); person.setFirstName("Alexander"); person.setLastName("K"); TableColumn firstNameCol = new TableColumn("First Name"); firstNameCol.setProperty("firstName"); TableColumn lastNameCol = new TableColumn("Last Name"); lastNameCol.setProperty("lastName"); table.getColumns().setAll(firstNameCol, lastNameCol); ObservableList teamMembers = FXCollections.observableArrayList(person); table.setItems(teamMembers); Scene scene = new Scene(table); stage.setScene(scene); stage.setVisible(true); } public static void main(String[] args) { launch(args); } } class Person { private StringProperty firstName; public void setFirstName(String value) { firstNameProperty().set(value); } public String getFirstName() { return firstNameProperty().get(); } public StringProperty firstNameProperty() { if (firstName == null) { firstName = new StringProperty(); } return firstName; } private StringProperty lastName; public void setLastName(String value) { lastNameProperty().set(value); } public String getLastName() { return lastNameProperty().get(); } public StringProperty lastNameProperty() { if (lastName == null) { lastName = new StringProperty(); } return lastName; } }