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 ?

Recommended Answers

All 2 Replies

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.

thanks ! it worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.