Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use Reflection to achieve that. For example, parse methods of your data class and create column for each one which ends with <code>Property</code>:</p> <pre><code>public class SmartTableView extends Application { private void populateColumns(Class clazz, TableView table) { for (Method method : clazz.getMethods()) { String name = method.getName(); if (name.endsWith("Property")) { String propName = name.replace("Property", ""); TableColumn column = new TableColumn(propName); column.setCellValueFactory(new PropertyValueFactory&lt;&gt;(propName)); table.getColumns().add(column); } } } @Override public void start(Stage primaryStage) { final ObservableList&lt;Person&gt; data = FXCollections.observableArrayList( new Person("Jacob", "Smith", "jacob.smith@example.com"), new Person("Isabella", "Dow", "isabella.dow@example.com"), new Person("Ethan", "Williams", "ethan.williams@example.com"), new Person("Emma", "Jones", "emma.jones@example.com"), new Person("Michael", "Brown", "michael.brown@example.com")); TableView table = new TableView(data); populateColumns(Person.class, table); Scene scene = new Scene(table, 300, 250); primaryStage.setTitle("Hello"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } public static class Person { private final SimpleStringProperty firstName; private final SimpleStringProperty lastName; private final SimpleStringProperty email; private Person(String fName, String lName, String email) { this.firstName = new SimpleStringProperty(fName); this.lastName = new SimpleStringProperty(lName); this.email = new SimpleStringProperty(email); } public String getFirstName() { return firstName.get(); } public void setFirstName(String fName) { firstName.set(fName); } public StringProperty firstNameProperty() { return firstName; } public String getLastName() { return lastName.get(); } public void setLastName(String fName) { lastName.set(fName); } public StringProperty lastNameProperty() { return lastName; } public String getEmail() { return email.get(); } public void setEmail(String fName) { email.set(fName); } public StringProperty emailProperty() { return lastName; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload