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
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);
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);