javaFX树结构treeview使用
//---------------------------------------------------在JavaFX Scene Builder里已经加了widget,设置了fx:id
1 @FXML 2 private TreeView<String> tv; 3 @Override 4 public void initialize(URL location, ResourceBundle resources) { 5 // TODO Auto-generated method stub 6 initTreeView(); 7 } 8 private void initTreeView(){ 9 TreeItem<String> item = new TreeItem<>("跟节点"); 10 tv.setRoot(item); 11 item.setExpanded(false); 12 TreeItem<String> i1 = new TreeItem<>("电影"); 13 TreeItem<String> i2 = new TreeItem<>("音乐"); 14 TreeItem<String> i3 = new TreeItem<>("游戏"); 15 item.getChildren().addAll(i1,i2,i3); 16 TreeItem<String> i4 = new TreeItem<>("荡寇风云"); 17 TreeItem<String> i5 = new TreeItem<>("变形金刚5"); 18 i1.setExpanded(false); 19 i1.getChildren().addAll(i4,i5); 20 21 }