This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Auto Scroll List/Scroll Pane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Auto Scroll List/Scroll Pane" Watch "Auto Scroll List/Scroll Pane" New topic
Author

Auto Scroll List/Scroll Pane

Jeffrey Smith
Greenhorn

Joined: Aug 21, 2004
Posts: 4
I have a JList in a JScroll Pane on my form, and everytime I add somethign to the list, I want it to scroll down, So I can see ther last Item entered (at the bottom). iright now, it adds the item to the bottom, but the view remains at the top, I tried making it select the last item on the list, but that didnt change the scroll pane view, but I cant figure out how to make the scroll pane go down to the bottom after each new entry.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
add this line after the code that adds to the listModel

list.ensureIndexIsVisible(listModel.size()-1);
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Jeffrey S.,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

We'd like something more than a single character for the displayed last name.

Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum..
Jeffrey Smith
Greenhorn

Joined: Aug 21, 2004
Posts: 4
OK that works exactly like I wanted it to, thanks.

i was using this before:
lstlog.setSelectedIndex (listModel_lstlog.size ());
it isnt all that diferent, but one thing, your worked.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Auto Scroll List/Scroll Pane
 
Similar Threads
JScrollBar/JScrollPane
Scrollable JList
JScrollPane with multiple JEditorPanes
JTree + JList in JScrollPane - Out of Sync
ScrollPane oversized for JTable