将TreeView添加到javafx中的TableCeell

时间:2014-02-25 17:45:13

标签: treeview javafx tableview

我需要为表格的特定列中的每个单元格添加一个TreeView。我能够添加字符串,但我无法添加TreeView。我怎样才能做到这一点? 这是我的NodeInfo类

public class NodeInfo{
private TreeView<String> nodeTree;
private TreeItem<String> root;
private final Image rootIcon=new Image(getClass().getResourceAsStream("/images/nodes.gif"));
private final Image folderIcon=new Image(getClass().getResourceAsStream("/images/folder.gif"));
public void settreeView(String s)
{
nodeTree = new TreeView<>();
    nodeTree.setEditable(true);
    root = new TreeItem<>("Rootnode", new ImageView(rootIcon));
    root.setExpanded(false);
    nodeTree.setRoot(root);
    for(int i=0;i<3; i++)
    {
    root.getChildren().add(new TreeItem<>(sharedFolders.get(i), new ImageView(folderIcon)));
    }
}
public TreeView<String> gettreeView()
{
 return nodeTree;
}
}

这是UI的控制器类

   public class GrapevineController implements Initializable {
   @FXML 
   private TableView<NodeInfo> tableView;
   @FXML
   private TableColumn<NodeInfo, TreeView<String>> nodeTree;
   @FXML
   private TableColumn<NodeInfo, String> name;
   @FXML
   private TableColumn<NodeInfo, String> favourite;
   @FXML
   private TableColumn<NodeInfo, String> updates;
   @FXML 
   public static ObservableList<NodeInfo> sourceTree = FXCollections.observableArrayList();
   @Override
     public void initialize(URL url, ResourceBundle r){
      tableView.setEditable(true);
    nodeTree.setCellValueFactory(new PropertyValueFactory<NodeInfo, TreeView<String>>   ("treeView"));
   name.setCellValueFactory(new PropertyValueFactory<NodeInfo, String>("MacAddress"));
   favourite.setCellValueFactory(new PropertyValueFactory<NodeInfo, String>("favourites"));
   updates.setCellValueFactory(new PropertyValueFactory<NodeInfo, String>("update"));

    tableView.setItems(sourceTree);


   }

0 个答案:

没有答案