Hello

I am currently designing tree to use in an instant messenger. I have the GUI working and have an array of strings that is dynamically created to show the tree structure on an instant messenger. The prob is that how do i associate the name on the JTree to a certain IP. i.e. when a user is clicked i want to retrieve what ip address from a database ,he is at so i can relay a message onto him. here is some of the code i have put together ......



private DefaultMutableTreeNode processHierarchy(Object hierarchy[]) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(hierarchy[0]);

DefaultMutableTreeNode child;
for (int i = 1; i < hierarchy.length; i++) {

Object nodeSpecifier = hierarchy[i];
if (nodeSpecifier instanceof Object[]) // Node with Child

child = processHierarchy((Object[]) nodeSpecifier);
else
child = new DefaultMutableTreeNode(nodeSpecifier); //Leaf

node.add(child);
}
return (node);
}







container = this.getContentPane();
container.setLayout(new GridLayout(1,2));
counterMain = new JPanel();
counterCal = new JPanel();
Object[] hierarchy =
{
"Buddy List",
new Object[] {
"Friends",
"Brendan",
"Steve",
"Shane",
"Johnny",
"Timmmy",
"Aoife",
"Paul",
},
//new Object[] { "Family", "Michael", "Anthony" },
//new Object[] { "Co Workers", "Michael", "John", "Diarmuid" }

};
buddylist = new JLabel("Instant Messenger List");
buddylist.setFont(new Font("Calfont", Font.BOLD, 14) );

DefaultMutableTreeNode root = processHierarchy(hierarchy);

tree = new JTree(root);

tree.addTreeSelectionListener(this);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

//Enable Tool Tips
ToolTipManager.sharedInstance().registerComponent(tree);


DefaultTreeCellRenderer renderer2 = new DefaultTreeCellRenderer();
renderer2.setOpenIcon(null);
renderer2.setClosedIcon(null);
renderer2.setLeafIcon(null);

//The next lines deals with icons
tree.setCellRenderer(renderer2);

scrollpane = new JScrollPane(tree,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR _AS_NEEDED);
//scrollpane.getViewport().add(tree);
counterMain.add(scrollpane, BorderLayout.WEST);

//Line to get the date
java.sql.Date date2 = new java.sql.Date((new GregorianCalendar()).getTime().getTime());
currentDate = date2.toString();
//System.out.println(currentDate);
counterCal.setLayout(new GridLayout(7,1));
label1 = new JLabel("Distributed Calander Interface");
label1.setBounds(0,30,0,0);
label1.setFont(new Font("Calfont", Font.BOLD, 14) );
time = new JLabel("Query Fields");
time.setBounds(20,20,20,20);
date = new JLabel("Current Date : "+currentDate);
date.setBounds(50,30,60,10);


//System.out.println("Before IMclock");
//System.out.println("After IMclock");

counterCal.setBackground(Color.lightGray);

counterCal.add(label1);
counterCal.add(date);
counterCal.add(time);
//counterCal.add(clockface);







container.setBackground(Color.green);
container.add(counterMain);
container.add(counterCal);
counterMain.add(buddylist);
counterMain.add(tree);
counterMain.setBackground(Color.white);



menubar = new JMenuBar();
file = new JMenu("File");
l_item = new JMenuItem("Logout");
e_item = new JMenuItem("Exit");
file.add(l_item);
file.add(e_item);
menubar.add(file);

friends = new JMenu("Friends");
conf = new JMenuItem("Start a conference...");
//conf.addActionListener(this);
friends.add(conf);
menubar.add(friends);

style = new JMenu("Style");
win_item = new JRadioButtonMenuItem("Windows");
//win_item.addItemListener(this);

met_item = new JRadioButtonMenuItem("Metal");
//met_item.addItemListener(this);

mot_item = new JRadioButtonMenuItem("Motif");
//mot_item.addItemListener(this);

style.add(win_item);
style.add(met_item);
style.add(mot_item);

ButtonGroup group = new ButtonGroup();
group.add(win_item);
group.add(met_item);
group.add(mot_item);
menubar.add(style);

help = new JMenu("Calendar");
about = new JMenuItem("View calendar");
help.add(about);
menubar.add(help);

this.setJMenuBar(menubar);

this.setSize(450, 600);
this.setLocation(565, 80);
this.setVisible(true);
this.setResizable(false);
this.setTitle("Kobe IM");