java - Binding HashMap<String, String> to MutableTreeNode -
i need bind hashmap
mutabletreenode
can display in jtree
.
i have following code:
static map<string, string> form = new linkedhashmap<string,string>();
i guess how need implement mutabletreenode
. don't know how procees key's of "form" show in mutabletreenode
.
public class mynode implements mutabletreenode { @override public enumeration children() { // todo auto-generated method stub return null; } @override public boolean getallowschildren() { // todo auto-generated method stub return false; } @override public treenode getchildat(int childindex) { // todo auto-generated method stub return null; } @override public int getchildcount() { // todo auto-generated method stub return 0; } @override public int getindex(treenode node) { // todo auto-generated method stub return 0; } @override public treenode getparent() { // todo auto-generated method stub return null; } @override public boolean isleaf() { // todo auto-generated method stub return false; } @override public void insert(mutabletreenode arg0, int arg1) { // todo auto-generated method stub } @override public void remove(int arg0) { // todo auto-generated method stub } @override public void remove(mutabletreenode arg0) { // todo auto-generated method stub } @override public void removefromparent() { // todo auto-generated method stub } @override public void setparent(mutabletreenode arg0) { // todo auto-generated method stub } @override public void setuserobject(object arg0) { // todo auto-generated method stub }
after mutabletreenode
correctly shows correct key
value, want able do:
final jtree tree = new jtree(); final defaultmutabletreenode customnode = new defaultmutabletreenode("custom"); defaulttreemodel tm = new defaulttreemodel(customnode); tree.setmodel(tm); (string str : form.keyset()) { mynode nod = new mynode(str); customnode.add(node); } tm.reload();
you want custom implementation of treemodel
interface. noted in how use trees: creating data model,
the
treemodel
interface accepts kind of object tree node. not require nodes representeddefaultmutabletreenode
objects, or nodes implementtreenode
interface.
although map<string, string>
not intrinsically hierarchical, may idea genealogymodel
, cited here, or filetreemodel
cited here , here.
Comments
Post a Comment