I m interested to know if it is possible to get pixel information about wherever mouse hovers on a button or Panel inside a JFrame. Any help is highly appreciated.
It just occurred to me that, although you didn't ask, you might want to know how to do that. If you are interested, you could look at How to Write a Mouse-Motion Listener.
A MouseListener or MouseMotionListener will return the location in pixels inside the component itself. That means that the top-left corner of the component is (0,0). To translate this to the screen itself you can check out which method of SwingUtilities to use for that.
Rob Prime wrote:A MouseListener or MouseMotionListener will return the location in pixels inside the component itself. That means that the top-left corner of the component is (0,0). To translate this to the screen itself you can check out which method of SwingUtilities to use for that.
The MouseEvent can provide that information without use of SwingUtilities.
I'm still not clear as to whether the OP wants to detect the location or the color of the pixel under the mouse.
luck, db
There are no new questions, but there may be new answers.
@paul : Yes... what I meant was how to do that . Thanks for giving link !
@ Burke: At this time, I had pixel location in my mind. But is it possible to get pixel color information ? If we can do that... it would be worth paying attention for. Can we do that ?
Rob Prime wrote:A MouseListener or MouseMotionListener will return the location in pixels inside the component itself. That means that the top-left corner of the component is (0,0). To translate this to the screen itself you can check out which method of SwingUtilities to use for that.
The MouseEvent can provide that information without use of SwingUtilities.
Jatin Dhingra wrote:@ Burke: At this time, I had pixel location in my mind. But is it possible to get pixel color information ? If we can do that... it would be worth paying attention for. Can we do that ?
The only way I know to get the pixel colour is from an Image. There are a few ways to get an Image for a specific location. I think the easiest way is to use java.awt.Robot and its createScreenCapture method. Note that the rectangle to take the screen shot of is relative to the screen. With the returned BufferedImage you can then call getRGB(int x, int y). So to get the colour of exactly one pixel, at (x, y) in screen coordinates: