PDA

Click to See Complete Forum and Search --> : popup menus - HELP!!


US101
Aug 16th, 2001, 03:45 AM
I have a JTree that looks something like this:

A
--B
----1
----2
----3
--C
----1
----2
----3


I want the user to be able to click on ANY child of B, (1,2,3), and ANY child of C, (1,2,3). I would like one menu to popup when I click a child of B and a different one to popup if a child of C.

Any Ideas

Thanks:confused:

US101
Aug 16th, 2001, 05:14 AM
I have managed to get this code so far:



public void mouseReleased(MouseEvent e) {
//Gets info about tree
//Row number
int curRow = tree.getClosestRowForLocation(e.getX(),e.getY());
//Path
TreePath curTP = tree.getPathForRow(curRow);
//Get Node
DefaultMutableTreeNode curTN = (DefaultMutableTreeNode)curTP.getLastPathComponent();
//Get info for curTN and place in node
//DefaultMutableTreeNode node = (DefaultMutableTreeNode) curTN.getUserObject();

if (e.isPopupTrigger()) {
if (curTN.getParent().toString() == "A") {
* Popup1.show(e.getComponent(), e.getX(), e.getY());
} else if (curTN.getParent().toString() == "B") {
* Popup2.show(e.getComponent(), e.getX(), e.getY());
}
}
}



It causes a NullPointerException where the * are