
import javafx.application.Application; 
import javafx.beans.Observable; 
import javafx.beans.property.SimpleStringProperty; 
import javafx.beans.property.StringProperty; 
import javafx.scene.Scene; 
import javafx.scene.control.TableColumn; 
import javafx.scene.control.TableView; 
import javafx.scene.control.cell.PropertyValueFactory; 
import javafx.scene.layout.BorderPane; 
import javafx.stage.Stage; 

public class Table extends Application { 
public static void main(String[] pArgs) {launch(pArgs);} 

public void start(Stage pStage) { 
final BorderPane pane = new BorderPane(); 
final Scene scene = new Scene(pane); 
pStage.setScene(scene); 

TableView<Person> table = new TableView<Person>(); 
Person person = new Person(); 
person.setFirstName("John"); 
person.setLastName("Snow"); 
person.setEmail("snow@north"); 
person.setEmployer("Dragon Queen"); 
person.setSalary("Kiss"); 
table.getItems().add(person); 

TableColumn<Person,String> firstNameCol = new TableColumn<>("First Name"); 
firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName")); 
TableColumn<Person,String> lastNameCol = new TableColumn<>("Last Name"); 
lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName")); 
TableColumn<Person,String> emailCol = new TableColumn<>("E-Mail"); 
emailCol.setCellValueFactory(new PropertyValueFactory("email")); 
TableColumn<Person,String> employerCol = new TableColumn<>("Employer"); 
employerCol.setCellValueFactory(new PropertyValueFactory("employer")); 
TableColumn<Person,String> salaryCol = new TableColumn<>("Salary"); 
salaryCol.setCellValueFactory(new PropertyValueFactory("salary")); 

table.getColumns().addListener((Observable pObs) -> { 
System.out.println("Columns:"); 
for(TableColumn<Person,?> col : table.getColumns()) { 
System.out.println(col.getText()); 
} 
System.out.println(""); 
}); 
table.getColumns().setAll(firstNameCol, lastNameCol, emailCol, employerCol, salaryCol); 

firstNameCol.setVisible(false); 
emailCol.setVisible(false); 

table.setTableMenuButtonVisible(true); 

pane.setCenter(table); 
pStage.show(); 
} 

public 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; 
} 

private StringProperty email; 
public void setEmail(String value) { emailProperty().set(value); } 
public String getEmail() { return emailProperty().get(); } 
public StringProperty emailProperty() { 
if (email == null) email = new SimpleStringProperty(this, "email"); 
return email; 
} 

private StringProperty employer; 
public void setEmployer(String value) { employerProperty().set(value); } 
public String getEmployer() { return employerProperty().get(); } 
public StringProperty employerProperty() { 
if (employer == null) employer = new SimpleStringProperty(this, "employer"); 
return employer; 
} 

private StringProperty salary; 
public void setSalary(String value) { salaryProperty().set(value); } 
public String getSalary() { return salaryProperty().get(); } 
public StringProperty salaryProperty() { 
if (salary == null) salary = new SimpleStringProperty(this, "salary"); 
return salary; 
} 
} 
} 