Why would you not want to implement MouseMotionListener?
The nice thing about Standards is that there are so many to choose from!
Joined: Nov 08, 2003
Because i'm listening to a TreeSelectionEvent,and when a event occurs ,the system want to popup a menu at the mouse's position, so i want to know the position without listening to a mouse event. is there any other solution? Thanks!
TreeSelectionEvent provides a TreePath of the selected nodes of the tree. You can then call the following methods of JTree to get information about the coordinates of the TreePath that was selected.
- getPathBounds( TreePath ) returns a Rectangle that gives you the bounds of the path.
- getRowForPath( TreePath ) returns the index of the selected row, and then you can use getRowBounds( int ) to get the bounds of that row.
You can use either of these methods to calculate a good point to launch a popup menu. Neither gives you the exact point that the mouse is at, but it really doesn't matter - all you want to do is pop up a menu on the selected nodes in the tree.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.