aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Tabbing in a JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Tabbing in a JScrollPane" Watch "Tabbing in a JScrollPane" New topic
Author

Tabbing in a JScrollPane

j wisard
Greenhorn

Joined: Jan 04, 2002
Posts: 2
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
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
j wisard
Greenhorn

Joined: Jan 04, 2002
Posts: 2
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tabbing in a JScrollPane
 
Similar Threads
scrollpane and panels
JScrollPane
Repaint my swing app
JList, clicking empty space selects last item
Adding ScrollPane to JPanel