4

I've been trying to build a Tree Table and define the cellValueFactories in FXML.

When I try this, I get the following error in the stack trace

Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: javafx.scene.control.TreeTableColumn$CellDataFeatures cannot be cast to javafx.scene.control.TableColumn$CellDataFeatures

The FXML is written as follows

<TreeTableView prefHeight="500.0" prefWidth="600.0" fx:id="customerContractsTable">
        <columns>
            <TreeTableColumn prefWidth="116.0" text="Contract Number">
                <cellValueFactory>
                    <PropertyValueFactory property=""/>
                </cellValueFactory>
            </TreeTableColumn>
    </columns>
</TreeTableView>

I've been trying to find any documentation references on how to do this and am coming up completely empty handed. Any documentation or help would be greatly apperciated.

LinkXXI
  • 314
  • 2
  • 13

3 Answers3

8

Here is a sample TreeTableView in FXML.

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

<?import javafx.scene.control.TreeTableView?>
<?import javafx.scene.control.TreeTableColumn?>
<?import javafx.scene.control.cell.TreeItemPropertyValueFactory?>

<TreeTableView>
    <columnResizePolicy>
        <TreeTableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
    </columnResizePolicy>
    <columns>
        <TreeTableColumn text="Contract Number">
            <cellValueFactory>
                <TreeItemPropertyValueFactory property="contractNumber" />
            </cellValueFactory>
        </TreeTableColumn>
    </columns>
</TreeTableView>

See RT-35233.

0

I think it's a bug, you should log it in the JavaFX issue tracker.

I think the bug is that the TreeTableView does not define it's own builder for defining columns in FXML, so it inherits the functionality from a TableViewBuilder which only defines columns as TableColumns, not TreeTableColumns. This means that TableColumns for straight TableViews can be defined in FXML but, TableColumns for TreeTableViews cannot.

In the meantime, define your cellValueFactories for TreeTables in code (in the initializer for your controller) rather than FXML.

jewelsea
  • 150,031
  • 14
  • 366
  • 406
0

I had the same problem but then checked and changed the imports. I was building a Dynamic Tableview and had used the "Fix Imports" feature of Netbeans, however I noticed that instead of importing: javafx.scene.control.TableColumn.CellDataFeatures; it had imported javafx.scene.control.TreeTableColumn.CellDataFeatures;

I corrected the import manually and the problem disappeared.