-
popup menus - HELP!!
I have a JTree that looks something like this:
Code:
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:
-
Here is my code so far
I have managed to get this code so far:
Code:
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