0

I have TreeTableView, and 1 column ine one, and 1 root item and 3 child item.

My init code:

public void init(){
    
        TreeTableView<String> treeTableViewFileName = controller.getTreeTableViewFileName();
    
        //Creating tree items
        TreeItem<String> childNode1 = new TreeItem<>("Child Node 1");
        TreeItem<String> childNode2 = new TreeItem<>("Child Node 2");
        TreeItem<String> childNode3 = new TreeItem<>("Child Node 3");
    
        //Creating the root element
        TreeItem<String> root = new TreeItem<>("Root");
        root.setExpanded(true);
    
        //Adding tree items to the root
        root.getChildren().setAll(childNode1, childNode2, childNode3);        

        TreeTableColumn<String, String> column1 = controller.getTreeColumnFileName();
        column1.setCellValueFactory(new TreeItemPropertyValueFactory<>("name"));
    
        treeTableViewFileName.setRoot(root); 
        treeTableViewFileName.setShowRoot(true); 
}

And after run app i show:

enter image description here

In TreeTableView i have 4 rows: 1 root and 3 child, but tree don't show content of items.

<Pane fx:id="pane3" prefHeight="280.0" prefWidth="917.0">
    <children>
       <TreeTableView fx:id="treeTableViewFileName" layoutX="14.0" layoutY="16.0" prefHeight="240.0" prefWidth="227.0">
         <columns>
           <TreeTableColumn fx:id="treeColumnFileName" prefWidth="199.0" text="FileName" />
         </columns>
       </TreeTableView>
    </children>
 </Pane>

Can someone help me? Thanks

kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • 1
    String has no property _name_ – kleopatra Jul 13 '22 at 07:30
  • also see the tutorial about how to use treetableview https://docs.oracle.com/javase/8/javafx/user-interface-tutorial/tree-table-view.htm#CJAFBAEG – kleopatra Jul 13 '22 at 07:38
  • i see it, i have error with: new ReadOnlyStringWrapper(p.getValue().getValue())); NetBeans show that i don't have method getValue() in p.getValue() – Yella32121 Jul 13 '22 at 08:02
  • I'd add an answer but it is closed. Assuming a column named `fileNameColumn` of type `TreeTableColumn`, where you want a cell factory with a read only property, set the cell value factory like this: `fileNameColumn.setCellValueFactory(p -> new ReadOnlyStringWrapper(p.getValue().getValue()).getReadOnlyProperty())`. In local testing, that worked fine for me. – jewelsea Jul 13 '22 at 19:46

0 Answers0