| Author |
how to get the mouse's position
|
mira yang
Ranch Hand
Joined: Nov 08, 2003
Posts: 33
|
|
Hello! how i can get the mouse's position without listening a mouse event? Thanks!
|
 |
Fuqiang Zhao
Greenhorn
Joined: Jan 07, 2004
Posts: 24
|
|
If you use jdk1.5, you can use the MouseInfo object, for details, please visit: http://java.sun.com/j2se/1.5.0/docs/api/java/awt/MouseInfo.html Hope that helps!
|
 |
mira yang
Ranch Hand
Joined: Nov 08, 2003
Posts: 33
|
|
|
but how to do in jdk1.4?
|
 |
Fuqiang Zhao
Greenhorn
Joined: Jan 07, 2004
Posts: 24
|
|
|
Use native methods.
|
 |
Eddie Vanda
Ranch Hand
Joined: Mar 18, 2003
Posts: 281
|
|
|
Why would you not want to implement MouseMotionListener?
|
The nice thing about Standards is that there are so many to choose from!
|
 |
mira yang
Ranch Hand
Joined: Nov 08, 2003
Posts: 33
|
|
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!
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
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.
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
mira yang
Ranch Hand
Joined: Nov 08, 2003
Posts: 33
|
|
|
Thank you!
|
 |
 |
|
|
subject: how to get the mouse's position
|
|
|