javaFX樹結構treeview使用
阿新 • • 發佈:2017-06-24
javafx 結構 ces sed resources resource 節點 stub generated
//---------------------------------------------------在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();View Code7 } 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 }
javaFX樹結構treeview使用