JavaFX I can´t fill tableview by observableList


i have problem with filling Tableview. When I run this code, my tableview has same number of records like Observablelist but nothing is visible.

Any idea? A donť understans some like cellvalueProperty. Is this usable for my example? Thanks.

 package SYSSEL;
 import java.sql.SQLException;
 import javafx.event.ActionEvent;
 import javafx.fxml.FXML;
 import javafx.scene.control.Button;
 import javafx.stage.Stage;
 import java.sql.ResultSet;
 import javafx.scene.control.*;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;

 public class gridOfMessages extends Stage {

   private ObservableList messages;
   private Button buttonCloseGrid;

   private TableColumn C1;

   private TableColumn C2;

   private TableColumn C3;

   private Button buttonRefreshGrid;

   private TableView<gridOfMessages> gridOfMessagesList;

   private void HandlerCloseGrid(ActionEvent event) {


   private void handlerRefreshGrid(ActionEvent event) throws ClassNotFoundException, SQLException {
     //Main Scene
     ResultSet rq = PdfSorting.checkNewMsgs();
       //Iterate Row;
       ObservableList<String> row = FXCollections.observableArrayList();
       System.out.println("Row [1] added "+row );



<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" minWidth="307.0" prefHeight="506.999977929685" prefWidth="307.0" xmlns:fx="" xmlns="" fx:controller="SYSSEL.gridOfMessages">
    <Button id="ButtonCloseGrid" fx:id="buttonCloseGrid" layoutX="0.0" layoutY="468.0" mnemonicParsing="false" onAction="#HandlerCloseGrid" prefHeight="39.0" prefWidth="147.0" text="Zavřít" />
    <Button id="refreshGrid" fx:id="buttonRefreshGrid" layoutX="147.0" layoutY="468.0" mnemonicParsing="false" onAction="#handlerRefreshGrid" prefHeight="39.0" prefWidth="161.0" text="Aktualizovat" />
    <TableView fx:id="gridOfMessagesList" layoutX="0.0" layoutY="0.0" prefHeight="468.0" prefWidth="307.0">
        <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="72.0" text="Číslo datovky" fx:id="C1" />
        <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="147.0" text="Cesta" fx:id="C2" />
        <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="87.0" text="BAN" fx:id="C3" />
10/14/2014 1:14:05 PM

Accepted Answer

Yes, you need to set cell value factory for every column in the table, that's for sure. But you should post your fxml file code too, without it I cannot confirm is it an issue here or not.

Cell value factory says from where value comes from. If your table data model type is gridOfMessages, then observable list for table data should be of the same type.


From your fxml file is obvious that you need to add cell value factory for every column, something like in the following example, just replace firstName with property name from your data model bean.

  <TableColumn text="First Name">
      <PropertyValueFactory property="firstName" />

If you don't set data type for TableView and ObservableList, default Object type will be assumed. Anyway, more than one column in the table is hard to make this way.


Then you need to write a class which will represent one table row. For example, if you want to have table with three columns, you need a bean with three properties. Then set this as a type for TableView and ObservableList, populate that list with data, and set it for the table, similar as it is in your code already. That should be in the controller class. This is a general description, because I don't know what this table should represent.

You can help also with Oracle's tutorial about how to show data in the table with fxml.

10/14/2014 1:51:17 PM

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