getting mouse location on scroll panes contents
How do you get the mouse location of the contents of a scroll pane if the scroll bars are not at 0,0? I tried implementing mouse motion listener, but when i move my mouse over the content, it always calls the scroll panes mouse motion listener(both the scroll pane and content have it implemented), not the contents. then I tried manually calling the contents listener from the scroll panes, but it still only gives coordinates relative to the scroll pane, not itself. Then I tried using the getVerticalScrollBar().getValue() method to add it to the coordinates given, but the problem with that is when the scroll bar is at 0, its value is 0, but when it is at 500(the max), its value is 553 or so, so it doesnt change linearly with moving the scroll bar. Are there any suggestions to this problem? i am trying to implement a canvas you can paint on that is variable size so it needs to be in a scroll pane.
Re: getting mouse location on scroll panes contents
I fail to understand any reason for adding a MouseMotionListener to a JScorllPane, but maybe you can explain how you intend to use it. To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
Why should a GUI component implement any kind of mouse listener? And regardless, it's what a listener is added to that matters; not the implementing class.
(both the scroll pane and content have it implemented)