Right Click Mouse problem in JTree

Hi' maybe this is simple problem, but i'm really stuck in here..can anyone help...

My problem is How to select node in JTree but using Right Click Mouse?

cos i want to display some JPopupMenu on the selected node so i can create action on it but i think i must to know first, which node is Selected...

If i'm using Left Click Mouse to select node, there is no problem, this can solve with getLastSelectedPathComponent()...but this is not i want..

i hope my question easy to understand..

thanks a lot...

[543 byte] By [2Puluh11Lapan3a] at [2007-10-3 3:20:45]
# 1

tree.addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent ev) {

TreePath path = tree.getPathForLocation(ev.getX(), ev.getY());

if (path == null) return;

tree.setSelectionPath(path);

}

public void mouseReleased(MouseEvent ev) {

if (tree.getPathForLocation(ev.getX(), ev.getY()) == null) return;

if (ev.isPopupTrigger()) { mnuPopup.show(tree, ev.getX(), ev.getY()); }

}

});

BinaryDigita at 2007-7-14 21:12:58 > top of Java-index,Desktop,Core GUI APIs...
# 2
Hey, it's really work...thanks a lot...u're the best man...
2Puluh11Lapan3a at 2007-7-14 21:12:58 > top of Java-index,Desktop,Core GUI APIs...