Created
October 12, 2011 05:25
-
-
Save khannedy/1280366 to your computer and use it in GitHub Desktop.
Membuat JTree Dinamis Sederhana
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Root | |
|_Child 1 | |
|_Child 2 | |
|_Child 3 | |
|_Child 4 | |
|_Child 5 | |
|_Child 6 | |
|_Child 7 | |
|_Child 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TreeModelCreator creator = new TreeModelCreator("Root"); | |
creator.addChild("Eko"); | |
creator.addChild("Kurniawan"); | |
creator.addChild("Khannedy"); | |
creator.addChild("StripBandunk"); | |
jTreeSample.setModel(creator.getModel()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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