Skip to content

Instantly share code, notes, and snippets.

@khannedy
Created October 12, 2011 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khannedy/1280366 to your computer and use it in GitHub Desktop.
Save khannedy/1280366 to your computer and use it in GitHub Desktop.
Membuat JTree Dinamis Sederhana
Root
|_Child 1
|_Child 2
|_Child 3
|_Child 4
|_Child 5
|_Child 6
|_Child 7
|_Child 8
TreeModelCreator creator = new TreeModelCreator("Root");
creator.addChild("Eko");
creator.addChild("Kurniawan");
creator.addChild("Khannedy");
creator.addChild("StripBandunk");
jTreeSample.setModel(creator.getModel());
/*
* Copyright (c) 2011, StripBandunk and/or its affiliates. All rights reserved.
*
* http://stripbandunk.com/
*
* STRIPBANDUNK PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package stripbandunk.tutorial.jtreedemo;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
/**
*
* @author Eko Kurniawan Khannedy
*/
public class TreeModelCreator {
private DefaultTreeModel model;
private DefaultMutableTreeNode root;
public TreeModelCreator(String rootData) {
root = new DefaultMutableTreeNode(rootData);
model = new DefaultTreeModel(root);
}
public void addChild(String child) {
root.add(new DefaultMutableTreeNode(child));
}
public TreeModel getModel() {
return model;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment