import javax.swing.* import javax.swing.tree.* import groovy.swing.* class MyNode extends DefaultMutableTreeNode { MyNode(params) { super(params) } public String toString() { return userObject?.name } } sb = new SwingBuilder() sb.edt { frame( title: "tree example", show: true, resizable: true, size: [300, 200], defaultCloseOperation: WindowConstants.EXIT_ON_CLOSE ){ scrollPane(){ tree(id:"tree", rootVisible: false) tree.model.root.removeAllChildren() def node1 = new MyNode([name:"Node1"]) node1.add(new MyNode([name:"Leaf1"])) node1.add(new MyNode([name:"Leaf2"])) tree.model.root.add(node1) tree.model.root.add(new MyNode([name:"Node2"])) tree.model.reload(tree.model.root) tree.expandRow(0) } } }実行時画面
動作環境
groovy 2.2.2, JDK 1.7 update55
0 件のコメント:
コメントを投稿