GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes MouseListener - mouseEntered question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "MouseListener - mouseEntered question." Watch "MouseListener - mouseEntered question." New topic
Author

MouseListener - mouseEntered question.

Andrew Gary
Greenhorn

Joined: Aug 31, 2011
Posts: 8

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


Thanks in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

It's a bit more CPU intensive, but a MouseMotionListener with mouseMoved can detect any movement of the mouse.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kili Liam
Greenhorn

Joined: Sep 27, 2011
Posts: 1
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

Joined: Oct 27, 2005
Posts: 19697
    
  20

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.
 
GeeCON Prague 2014
 
subject: MouseListener - mouseEntered question.