Results 1 to 2 of 2
  1. #1
    yemista is offline Member
    Join Date
    Oct 2011
    Posts
    41
    Rep Power
    0

    Default 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.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default 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.

    (both the scroll pane and content have it implemented)
    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.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Formatting contents within Tabbed Panes
    By Redefine12 in forum AWT / Swing
    Replies: 6
    Last Post: 03-21-2012, 04:11 PM
  2. Replies: 5
    Last Post: 09-28-2011, 05:43 PM
  3. Location of Mouse/JRadioButton Problem
    By PorgrammingNoob117 in forum AWT / Swing
    Replies: 3
    Last Post: 05-10-2011, 10:01 PM
  4. Mouse scroll capture (GUI independent under linux)
    By krimen_sp in forum Advanced Java
    Replies: 1
    Last Post: 04-22-2011, 10:51 PM
  5. How do you set the mouse curser location?
    By noobgrammer in forum New To Java
    Replies: 1
    Last Post: 07-20-2010, 01:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •