File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MouseListener - mouseEntered question.

 
Andrew Gary
Greenhorn
Posts: 8
Chrome Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to determine if the mouse enters something like a JButton or JTextField, but is there a way to determine if the mouse enters a certain portion of the JFrame?

Thanks
-Andrew
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a bit more CPU intensive, but a MouseMotionListener with mouseMoved can detect any movement of the mouse.
 
Kili Liam
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

You can create a Rectangle(...) and while the mouse is moving in the frame, you use the contains(..) method of the Rectangle class to determine if the mouse just entered "your" portion of the JFrame.

KL
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why create a Rectangle for that? That calculation is easy enough:
For the region with (x1, y1) as the top-left corner and (x2, y2) as the bottom-right corner, and (x, y) the current point.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic