Results 1 to 4 of 4
  1. #1
    Thez is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default MouseMotionListener 'scrolling'

    I want to be able to navigate my way across a JPanel by using the mouse movement alone.

    If for instance my desktop resolution (or JFrame/JPanel size) is 1280x1024 and my JPanel is 3000x3000, then when my mouse gets to the edge of the JFrame/JPanel, it should move/scroll towards the direction the mouse is going to.

    If I set my mouse to the right edge of the screen, the view should shift to the right till I move my mouse back again.
    Its like scrolling over a gamefield using the mouse to navigate.

    Any ideas on how this could be done?

  2. #2
    strati1991 is offline Member
    Join Date
    Mar 2009
    Posts
    13
    Rep Power
    0

    Default

    You could init a BufferedImage with the size 3000*3000 and just draw on the JPanel just the Subimage of 1280x1024 by jusing BufferedImage.getSubimage().To move this rect you have to init a extend a mouseMotion listener to the JPanel and test if the mouse comes to the borders and then you have to get another subimage and draw it into the panel.I don't know if this is fast enought you have to test it...

  3. #3
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    use MouseMotionListener
    your JFrame/JPanel add to the listener
    implements mouseMoved(MouseEvent e)
    can get the x, y pos of the mouse,
    check is edge, move the view of JFrame/JPanel

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Isn't the original post a bit long in the tooth, having been posted in 2007?

Similar Threads

  1. Replies: 1
    Last Post: 03-28-2008, 10:26 AM
  2. Applet with scrolling status line
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-10-2008, 02:53 PM
  3. AWT Table Scrolling
    By albert_kam in forum AWT / Swing
    Replies: 0
    Last Post: 01-03-2008, 11:37 AM
  4. Scrolling with JTables
    By hiranya in forum AWT / Swing
    Replies: 5
    Last Post: 10-30-2007, 08:48 AM
  5. JScrollPane not scrolling
    By Riftwalker in forum Advanced Java
    Replies: 2
    Last Post: 07-17-2007, 08:16 PM

Posting Permissions

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