Over a million developers have joined DZone.

A simple JavaFX 2.0 TableView example

DZone's Guide to

A simple JavaFX 2.0 TableView example

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

I wanted to quickly show the current state of how a TableView may be built in JavaFX 2.0. I just copied the demo created by Adam Bien, and pasted it into my blog software, so apologies for typos. The approach shown here depends on the data that is backing the TableView being a Bean – if this is the case you can simply provide the relevant PropertyReference for that column and it’ll be populated as expected.

There are alternative approaches to this style that are also supported – Adam shows one such approach in his blog post. I am keen to hear what people out there think about the API that Adam and I have shown in our posts, and what else you would like to see.

The code below creates a TableView that is populated from an ObservableList. This means that should this collection ever be modified, the TableView will immediately be updated to reflect these changes. It even watches the provided properties of the Person objects, such that if the Person.FIRST_NAME or Person.LAST_NAME values change for any visible row, that cell will automatically be refreshed also.

Before I get to the code, I just want to add the normal, but very important disclaimer: this code is written using an API that isn’t public yet. By the time it is public, it may have changed drastically. Do not assume anything you see here will be in the final API. Also, this code sample is my own creation (and derived from Adam’s linked above) – it is not provided by Oracle and does not represent them.

import javafx.application.Application;
import javafx.application.Launcher;
import javafx.collections.FXCollections;
import javafx.collections.Sequence;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.table.TableColumn;
import javafx.scene.control.table.TableView;
import javafx.scene.control.table.model.SequenceTableModel;
import javafx.stage.Stage;

public class Main extends Application {

public void start() {
Stage stage = new Stage();
stage.setTitle("Hello Table");

final Group root = new Group();
Scene scene = new Scene(root);

Sequence children = root.getChildren();


public TableView getTableView() {
ObservableList<Person> data = FXCollections.<Person>sequence(
new Person("Duke", "Java"),
new Person("DukeFX", "JavaFX"));

TableView<Person> tableView = new TableView<Person>();

TableColumn firstNameCol = new TableColumn("First");

TableColumn lastNameCol = new TableColumn("Last");

tableView.getColumns().addAll(firstNameCol, lastNameCol);

return tableView;

public static void main(String[] args) {
Launcher.launch(Main.class, args);

public class Person implements Bean {

private String firstName;
private String lastName;

public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;

//with getters and other Bean functionality



From http://jonathangiles.net/blog/?p=998

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}