Results 1 to 3 of 3
  1. #1
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default How to autoscroll a JScrollPane

    I have done a bit of research and all the solutions I have found deal with JTextArea and scrolling to the bottom. My situation is different. I have a stack of JTextfields vertically aligned. What I want is when you are in the last visible text field and you hit tab to the next one, the scrollpane will automatically scroll up to make that text field visible. Is this possible?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    Assuming the JTextFields are contained in a JPanel (panel), something like
    Java Code:
    panel.scrollRectToVisible(((Component) e.getSource()).getBounds());
    in a FocusListener#focusGained, attached to each text field.

    db

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    SWEET!

    Once I worked out which panel to call it on, I got it working.

    Thanks a lot Darryl.

Similar Threads

  1. Autoscroll website
    By Eliteoomph in forum New To Java
    Replies: 2
    Last Post: 02-09-2011, 09:33 PM
  2. Help with jScrollPane
    By weikang in forum SWT / JFace
    Replies: 1
    Last Post: 02-04-2011, 03:30 AM
  3. Chat window autoscroll lockes scrollbar at buttom
    By ZacK.YoveL in forum AWT / Swing
    Replies: 2
    Last Post: 06-25-2010, 11:19 PM
  4. dragging the row header autoscroll
    By Allgorythm in forum New To Java
    Replies: 6
    Last Post: 02-15-2010, 05:10 AM
  5. jscrollpane
    By kaemonsaionji in forum New To Java
    Replies: 3
    Last Post: 02-25-2009, 08:39 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
  •