2 Replies Latest reply: Jun 20, 2013 9:57 AM by b3c5bf89-3812-4c5c-b002-1ca245d8ee49 RSS

    JavaFX 2.2 TableView

      My doubt is TableView with FXML because i did one app on swing(JavaFx) and is very easy, but with FXML the data isn't showing on the table i don't understand the reason.

      public class SampleController {

      @FXML TableView<InvoiceEntry> invoiceTbl;
      @FXML TableColumn itemIdCol;
      @FXML TableColumn itemNameCol;
      @FXML TableColumn itemQtyCol;
      @FXML TableColumn itemPriceCol;
      @FXML Button addItemBtn;

      private void handleButtonAction() {

      ObservableList<InvoiceEntry>data = FXCollections.observableArrayList();
      System.out.println("You clicked me!");
      InvoiceEntry entry = new InvoiceEntry();
      int itemNum=0;
      for (int i = 0; i < 10; i++) {
      entry.itemName.set("Item " + itemNum);
      entry.price.set("" + (1.99 + itemNum) );
      entry.qty.set(itemNum + 10);


      itemIdCol.setCellValueFactory(new PropertyValueFactory<InvoiceEntry,Integer>("itemId"));
      itemNameCol.setCellValueFactory(new PropertyValueFactory<InvoiceEntry,String>("itemName"));
      itemQtyCol.setCellValueFactory(new PropertyValueFactory<InvoiceEntry,Integer>("qty"));
      itemPriceCol.setCellValueFactory(new PropertyValueFactory<InvoiceEntry,String>("price"));

      // create the data


      class InvoiceEntry {

      public Integer itemId;
      public SimpleStringProperty itemName = new SimpleStringProperty("<Name>");
      public SimpleStringProperty price = new SimpleStringProperty();
      public SimpleIntegerProperty qty = new SimpleIntegerProperty();
      public int invoiceId;

      public Integer getItemId() {
      return itemId;

      public String getItemName() {
      return itemName.get();

      public String getPrice() {
      return price.get();

      public Integer getQty() {
      return qty.get();

      public class JavaFXApplication6 extends Application{

      public void start(Stage stage) throws Exception {
      Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));

      Scene scene = new Scene(root);


      * The main() method is ignored in correctly deployed JavaFX application.
      * main() serves only as fallback in case the application can not be
      * launched through deployment artifacts, e.g., in IDEs with limited FX
      * support. NetBeans ignores main().
      * @param args the command line arguments
      public static void main(String[] args) {


      <?import java.lang.*?>
      <?import java.util.*?>
      <?import javafx.scene.*?>
      <?import javafx.scene.control.cell.PropertyValueFactory?>
      <?import javafx.scene.control.*?>
      <?import javafx.scene.layout.*?>

      <AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="javafxapplication6.SampleController">
      <TableView id="" fx:id="invoiceTbl" layoutX="14.0" layoutY="14.0" prefHeight="341.0" prefWidth="427.0">
      <TableColumn fx:id="itemIdCol" text="ID" >

      <TableColumn text="Item Name" fx:id="itemNameCol" />
      <TableColumn text="Qty" fx:id="itemQtyCol" />
      <TableColumn text="Price" fx:id="itemPriceCol" />
      <Button fx:id="addItemBtn" layoutX="14.0" layoutY="355.0" mnemonicParsing="false" onMouseClicked="#handleButtonAction" text="Add Item" />

      the Error is:*bold* SEVERE: javafx.scene.control.Control loadSkinClass Failed to load skin 'StringProperty [bean: TableRow[id=null, styleClass=cell indexed-cell table-row-cell], name: skinClassName, value: com.sun.javafx.scene.control.skin.TableRowSkin]' for control TableRow[id=null, styleClass=cell indexed-cell table-row-cell]
      java.lang.RuntimeException: java.lang.IllegalAccessException: Class com.sun.javafx.property.PropertyReference can not access a member of class javafxapplication6.InvoiceEntry with modifiers "public"
        • 1. Re: JavaFX 2.2 TableView
          There are many problem with your code.

          First : the Error you post can be fix if you set your class InvoiceEntry to public (public class InvoiceEntry {} )
          Second : is your code still can not running if you keep this LOC :
          Your FXML have already define those column so adding them again will generate error.
          Third : You leave this LOC : "data.add(entry);" out of the loop so your table will have one row instead of 10.

          Hope this will help
          • 2. Re: JavaFX 2.2 TableView

            Hi, has passed a lot, but I had a similar problem, and in my case, I changed the name of the class used in the element, "menu-button" became "menuButton", this solved my problem, hope it can help them.