Hello, I have the current problem. As it stands im working on an ImageViewer project. I'm having trouble determining the mouse location for what I think are the following reasons.

I currently have the frame, and within that frame is a JTabbedPane.

Each tab is a new object, which creates a new ImagePanel nested inside a JScrollPane. I've tried determining the x,y location of the mouse through

imagepanel.getmouselocation();

to no avail. It gives me the mouse location in regards to the top left hand side of the JFrame. Is it possible to get the X,Y locations from within a scrollable component? Thanks , if you need any more info feel free to ask :).

Ross.

What do you need to use them for? Typically you would get them from a MouseEvent with a MouseMotionListener on the component that needs to respond to them.

What do you need to use them for? Typically you would get them from a MouseEvent with a MouseMotionListener on the component that needs to respond to them.

I currently have a popupmenu that ties to each ImagePanel I right click and choose what transform/effect/filter I want to apply. I want to add another function to that, which gets the colour of the currently selected pixel and displays its RGB values. Just to the console at the moment.

Ah, it was as simple as that, now I just feel foolish... Thanks :)

I dropped a label into a scroll pane and loaded an image that was larger than the viewport and checked mouse coords from label.getMousePosition(). They seem to work just fine. The coords are in the coordinate space of the scrollable target (ie they aren't limited to the visible dimensions of the scroll pane component.)

edit: Glad you got it working. There are usually several ways to get there with Swing :)

Edited 6 Years Ago by Ezzaral: n/a

This article has been dead for over six months. Start a new discussion instead.