aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes how to get the mouse's position Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to get the mouse Watch "how to get the mouse New topic
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get the mouse's position