everything seems to run fine apart from the if statement, comments in code explain most of it.
The aim is to add two ArrayLists to a Jtree. Arraylist containing whole numbers like (1,2,3,4 etc) and the second containing double number like (1.1,1.2,2.1 etc).
I want to add the first array to the JTree, which i have managed to do. But i then want to add the second arraylist so thats it is a child of the first.
So that 1.1 and 1.2 are a child of 1 and 2.1 is a child of 2 etc.
Any help would be appreciated.
DisplayTree.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frameG2 = new JFrame("Cell Tree");
frameG2.setSize( 400, 900 );
frameG2.setVisible(true);
frameG2.setBackground( Color.gray );
DefaultMutableTreeNode root = new DefaultMutableTreeNode("cells");
int i=0;
//should through first array list and adds it to root
for (int n =0; n<arrayList.size();n++) {
DefaultMutableTreeNode cells = new DefaultMutableTreeNode(arrayList.get(n));
root.add(cells);
//should go through jtree elements
Enumeration search = root.postorderEnumeration();
while(search.hasMoreElements()){
//should compare each element to a 2nd array
//2nd array consists of double numbers like 1.1,1.2,2.1 etc
//so i split it before the "." so 1.1 is 1
//first array consists of whole numbers like 1, 2, 3
//want to make 1.1 child of 1 etc.
if (search.nextElement().toString()==(arrayList2.get(i).toString().split("\\.", 0)[0])) {
DefaultMutableTreeNode NewCells = new DefaultMutableTreeNode(arrayList2.get(i));
cells.add(NewCells);
i++;
}else{
}
}
}
tree = new JTree(root);
frameG2.add(tree);
}
});