JavaFX TableView data not visible with CellValueFactory


I'm working on a finance control type application for my parents in Java using JavaFX, but I'm having a problem with the GUI. I've searched Google and the code for a problem, but I can't seem to find anything wrong.

This is the link I'm using as a guideline:

I'm starting off with a Calender using TableView. By the way, is there any other way I can make a calender with JavaFX?

Anyways, here is the code:

package Finance;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main extends Application {
    Calendar calendar = new GregorianCalendar();
    private TableView<Week> table = new TableView<Week>();

    final ObservableList<Week> data = FXCollections.observableArrayList(
            new Week("1", "2", "3", "4", "5", "6", "7")

    public void start(Stage primaryStage) throws Exception {
        Scene scene = new Scene(new Group());
        primaryStage.setTitle("Finance Control");

        Label month = new Label(getMonthForInt(calendar.get(Calendar.MONTH)));
        month.setFont(new Font("Arial", 30));


        TableColumn sun = new TableColumn("Sunday");
        TableColumn mon = new TableColumn("Monday");
        TableColumn tue = new TableColumn("Tuesday");
        TableColumn wed = new TableColumn("Wednesday");
        TableColumn thu = new TableColumn("Thursday");
        TableColumn fri = new TableColumn("Friday");
        TableColumn sat = new TableColumn("Saturday");

                new PropertyValueFactory<Week, String>("a")

                new PropertyValueFactory<Week, String>("b")

                new PropertyValueFactory<Week, String>("c")

                new PropertyValueFactory<Week, String>("d")

                new PropertyValueFactory<Week, String>("e")

                new PropertyValueFactory<Week, String>("f")

                new PropertyValueFactory<Week, String>("g")

        TableColumn[] days = {sun, mon, tue, wed, thu, fri, sat};
        for (TableColumn day: days) {

        table.getColumns().addAll(sun, mon, tue, wed, thu, fri, sat);

        final VBox vbox = new VBox();
        vbox.setPadding(new Insets(10, 0, 0, 10));
        vbox.getChildren().addAll(month, table);
        ((Group) scene.getRoot()).getChildren().addAll(vbox);


    String getMonthForInt(int num) {
        String month = "wrong";
        DateFormatSymbols dfs = new DateFormatSymbols();
        String[] months = dfs.getMonths();
        if (num >= 0 && num <= 11 ) {
            month = months[num];
        return month;

    public static void main(String[] args) {

    public static class Week {
        String a;
        String b;
        String c;
        String d;
        String e;
        String f;
        String g;

        public Week(String a, String b, String c, String d, String e, String f, String g) {
            this.a = a;
            this.b = b;
            this.c = c;
            this.d = d;
            this.e = e;
            this.f = f;
            this.g = g;

This is what happens when I run it. I would expect it to populate with the values I gave the Constructor of the Week object, but it isn't - it just shows empty cells.

I'm using IDEA IDE if that matters... I'd be grateful for any help with this or any comments. I'll probably be using scenebuilder at some point, but I wanted to get a feel for the actual code first before going to the GUI builder.

1/20/2014 4:01:23 AM

Accepted Answer

Ahh, it appears I've solved it. The PropertyValueFactory class uses the methods in the week class to get the values - I simply needed to add some getters for all of the fields.

1/20/2014 4:23:06 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow