Hi. I have created an application wherein I am showing a large image inside a JScrollPane .

As I move my mouse over the image within the jscrollpane i want to display the RGB values of the pixel under the mouse pointer on a status bar.

I am able to retrieve mouse coordinates relative to the jscrollpane , but when I scroll down I still get the same moouse coordinates . How do I know by how many pixels have I scrolled down , so that I can add that to the Y coordinate of the mouse ?

for the "beginning" of the scrollbar

scrollPaneVar.getHorizontalScrollBar().getValue();
scrollPaneVar.getVerticaalScrollBar().getValue();

Add these values to the above values to get the "end" of the scrollbar

scrollPaneVar.getHorizontalScrollBar().getModel().getExtent();
scrollPaneVar.getVerticaalScrollBar().getModel().getExtent();

Divide those summed values by 2 to get the "middle" of the scrollbar.

See the API docs for JScrollPane, JScrollBar, and BoundedRangeModel.

Edited 6 Years Ago by masijade: n/a

This question has already been answered. Start a new discussion instead.