Pular para o conteúdo principal

Postagens

Mostrando postagens de setembro, 2012

Showing Object Properties in a TableView

This post is not to talk about any specific app but to show a simple How-To with TableView.  Show values in a table in JavaFX is easy. You can show an object property with a few lines of code since we have classes that allows you to produce cells that read directly from the object. For example, let's say we have a class Person that contains two properties: public class Person { private String name; private int id; //getters, setters.. } If you want to create to columns to show the id and name properties, you need to create two columns and inform each column a PropertyValueFactory object instance: TableView tableView = new TableView (); TableColumn idColumn = new TableColumn ("Id"); idColumn.setCellValueFactory(new PropertyValueFactory ("id")); TableColumn nameColumn = new TableColumn ("Name"); nameColumn.setCellValueFactory(new PropertyValueFactory ("name")); tableView.getColumns().addAll(idColumn, nameColumn); Let's ...