Reputation: 79
I have a JTree. When i select a node from Jtree , I want to display selected node.
DefaultMutableTreeNode selectedNode=(DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
type=selectedNode.toString();
this code is working perfectly for Left click,but when i use it for right mouse click it wont get selected nor displayed.
Upvotes: 0
Views: 72
Reputation: 1882
can you try this method?
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
int row = tree.getClosestRowForLocation(e.getX(), e.getY());
tree.setSelectionRow(row);
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
Upvotes: 1