/* * 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.SimpleStringProperty; 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.scene.control.cell.PropertyValueFactory; import javafx.stage.Stage; /** * * @author Alexander Kouznetsov */ public class Main 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.setCellValueFactory(new PropertyValueFactory("firstName")); TableColumn lastNameCol = new TableColumn("Last Name"); lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName")); table.getColumns().setAll(firstNameCol, lastNameCol); ObservableList teamMembers = FXCollections.observableArrayList(person); table.setItems(teamMembers); Scene scene = new Scene(table); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } public static 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 SimpleStringProperty(this, "firstName"); 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 SimpleStringProperty(this, "lastName"); return lastName; } } }