Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8828909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:42:51+00:00 2026-06-14T07:42:51+00:00

So i am trying to learn how to use JavaFx Tableview and i stumpled

  • 0

So i am trying to learn how to use JavaFx Tableview and i stumpled across this tutorial:

Oracle tableview tutorial

in this tutorial they show that in order to fill you tableView you have to fill it with Strings, but not just any String you have to format you String to a SimpleStringProperty

i tried without the format and the result was that none of the information would show!

Also i found that if you want to add an Integer to the table you would have to declare it as an SimpleIntegerProperty

Now i am fairly new to JavaFx but does this mean that when i create an object i have to format all my Integers and Strings to be able to fill my TableView? it seems rather stupid but maybe there is a higher purpose? or is there a way to avoid it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:42:52+00:00Added an answer on June 14, 2026 at 7:42 am

    You don’t need to use Properties in your table data objects for them to display, although use of Properties in certain circumstances is desirable.

    The following code will display a table of people based on a Person class which has only String fields.

    import javafx.application.Application;
    import javafx.collections.*;
    import javafx.geometry.Insets;
    import javafx.scene.*;
    import javafx.scene.control.*;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.layout.VBox;
    import javafx.scene.text.Font;
    import javafx.stage.Stage;
    
    public class ReadOnlyTableView extends Application {
      private TableView<Person> table = new TableView<Person>();
      private final ObservableList<Person> data =
        FXCollections.observableArrayList(
          new Person("Jacob", "Smith", "jacob.smith@example.com"),
          new Person("Isabella", "Johnson", "isabella.johnson@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")
        );
    
      public static void main(String[] args) { launch(args); }
    
      @Override public void start(Stage stage) {
        stage.setTitle("Table View Sample");
        stage.setWidth(450);
        stage.setHeight(500);
    
        final Label label = new Label("Address Book");
        label.setFont(new Font("Arial", 20));
    
        TableColumn firstNameCol = new TableColumn("First Name");
        firstNameCol.setMinWidth(100);
        firstNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
    
        TableColumn lastNameCol = new TableColumn("Last Name");
        lastNameCol.setMinWidth(100);
        lastNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));
    
        TableColumn emailCol = new TableColumn("Email");
        emailCol.setMinWidth(200);
        emailCol.setCellValueFactory(new PropertyValueFactory<Person, String>("email"));
    
        table.setItems(data);
        table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
    
        final VBox vbox = new VBox();
        vbox.setSpacing(5);
        vbox.setPadding(new Insets(10, 0, 0, 10));
        vbox.getChildren().addAll(label, table);
    
        stage.setScene(new Scene(new Group(vbox)));
        stage.show();
      }
    
      public static class Person {
        private String firstName;
        private String lastName;
        private String email;
    
        private Person(String fName, String lName, String email) {
          this.firstName = fName;
          this.lastName = lName;
          this.email = email;
        }
    
        public String getFirstName() { return firstName; }
        public void setFirstName(String fName) { firstName = fName; }
        public String getLastName() { return lastName; }
        public void setLastName(String lName) { lastName = lName; }
        public String getEmail() { return email; }
        public void setEmail(String inMail) { email = inMail; }
      }
    }
    

    Explanation

    The purpose of using Properties and ObservableLists is that these are listenable elements. When properties are used, if the value of a property attribute in the datamodel changes, the view of the item in the TableView is automatically updated to match the updated datamodel value. For example, if the value of a person’s email property is set to a new value, that update will be reflected in the TableView because it listens for the property change. If instead, a plain String had been used to represent the email, the TableView would not refresh as it would be unaware of email value changes.

    The PropertyValueFactory documentation describes this process in detail:

    An example of how to use this class is:

    TableColumn<Person,String> firstNameCol = new TableColumn<Person,String>("First Name");
    firstNameCol.setCellValueFactory(new PropertyValueFactory<Person,String>("firstName"));  
    

    In this example, the “firstName” string is used as a reference to an
    assumed firstNameProperty() method in the Person class type (which is
    the class type of the TableView items list). Additionally, this method
    must return a Property instance. If a method meeting these
    requirements is found, then the TableCell is populated with this
    ObservableValue. In addition, the TableView will automatically add an
    observer to the returned value, such that any changes fired will be
    observed by the TableView, resulting in the cell immediately updating.

    If no method matching this pattern exists, there is fall-through
    support for attempting to call get() or is() (that
    is, getFirstName() or isFirstName() in the example above). If a method
    matching this pattern exists, the value returned from this method is
    wrapped in a ReadOnlyObjectWrapper and returned to the TableCell.
    However, in this situation, this means that the TableCell will not be
    able to observe the ObservableValue for changes (as is the case in the
    first approach above).

    Update

    Here is a contrasting example to the first example which demonstrates how a TableView can observe and automatically refresh based on changes to it’s ObservableList of items and changes to the value of a property based item attribute.

    import javafx.application.Application;
    import javafx.beans.property.*;
    import javafx.collections.*;
    import javafx.event.*;
    import javafx.geometry.Insets;
    import javafx.scene.*;
    import javafx.scene.control.*;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.layout.VBox;
    import javafx.scene.text.Font;
    import javafx.stage.Stage;
    
    public class PropertyBasedTableView extends Application {
      private TableView<Person> table = new TableView<Person>();
      private final ObservableList<Person> data = FXCollections.observableArrayList();
      private void initData() {
        data.setAll(
          new Person("Jacob", "Smith", "jacob.smith@example.com"),
          new Person("Isabella", "Johnson", "isabella.johnson@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")
        );
      }
    
      public static void main(String[] args) { launch(args); }
    
      @Override public void start(Stage stage) {
        initData();
    
        stage.setTitle("Table View Sample");
        stage.setWidth(450);
        stage.setHeight(500);
    
        final Label label = new Label("Address Book");
        label.setFont(new Font("Arial", 20));
    
        TableColumn firstNameCol = new TableColumn("First Name");
        firstNameCol.setMinWidth(100);
        firstNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
    
        TableColumn lastNameCol = new TableColumn("Last Name");
        lastNameCol.setMinWidth(100);
        lastNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));
    
        TableColumn emailCol = new TableColumn("Email");
        emailCol.setMinWidth(200);
        emailCol.setCellValueFactory(new PropertyValueFactory<Person, String>("email"));
    
        table.setItems(data);
        table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
        table.setPrefHeight(300);
    
        final Button setEmailButton = new Button("Set first email in table to wizard@frobozz.com");
        setEmailButton.setOnAction(new EventHandler<ActionEvent>() {
          @Override public void handle(ActionEvent event) {
            if (data.size() > 0) {
              data.get(0).setEmail("wizard@frobozz.com");
            }  
          }
        });
    
        final Button removeRowButton = new Button("Remove first row from the table");
        removeRowButton.setOnAction(new EventHandler<ActionEvent>() {
          @Override public void handle(ActionEvent event) {
            if (data.size() > 0) {
              data.remove(0);
            }  
          }
        });
    
        final Button resetButton = new Button("Reset table data");
        resetButton.setOnAction(new EventHandler<ActionEvent>() {
          @Override public void handle(ActionEvent event) {
            initData();
          }
        });
    
        final VBox vbox = new VBox(10);
        vbox.setPadding(new Insets(10, 0, 0, 10));
        vbox.getChildren().addAll(label, table, setEmailButton, removeRowButton, resetButton);
    
        stage.setScene(new Scene(new Group(vbox)));
        stage.show();
      }
    
      public static class Person {
        private final StringProperty firstName;
        private final StringProperty lastName;
        private final StringProperty 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 lName) { lastName.set(lName); }
        public StringProperty lastNameProperty() { return lastName; }
        public String getEmail() { return email.get(); }
        public void setEmail(String inMail) { email.set(inMail); }
        public StringProperty emailProperty() { return email; }  // if this method is commented out then the tableview will not refresh when the email is set.
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn to use Map with Jaxb. I did this: @XmlElementWrapper(name =
I'm trying to learn to use Ruby on Rails (going through Hartl's tutorial for
I'm trying to learn to use ANTLR, and seem to have come across an
I am trying to learn how to use generators, so I wrote this one,
I am trying to learn to use KendoUI. I did a small tutorial and
I am trying to learn to use JavaCC and realized that it has support
I am trying learn the use of lambda expressions and hence still struggling to
I am trying to learn and use an SDK for a vendor's product. Unfortunately,
I am trying to learn to use buffer overflow attack in Ubuntu. Unfortunately, I
I am trying to learn to use the wx packages to make GUI programs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.