• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tabbing in a JScrollPane

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I haved added a JPanel to a JScrollPane. The JPanel contains multiple JTextFields arrayed vertically (using a GridBagLayout). When I tab from one JTextField to another, I would like the JScrollPane to scroll down to display the JTextField that currently has the focus.
Does anyone know how to do this?
Thanks,
-Jeff Wisard
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, Jeff, please change your user name from jwisard to something that follows the JavaRanch Username Convention like Jeff Wisard...

Next... on to the problem... it sounds simple enough to solve... Just add a FocusListener to your JTextFields that looks something like the following...



However, the behavior of scrollRectToVisible( Rectangle ) sometimes breaks... so you'll have to mess with it to get something appropriate to your layout... ( The following listener almost works perfectly with the previous code... it still jumps around a bit more than I like, though... )



-Nate
 
j wisard
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic