JList Scrollbar -- keep is at bottom

I am using a JList to display a list of messages. When I add messages to the bottom of the list I would like the JList to keep displaying the end of the list. However, it's default is to remain in the same location as message are added. How do I change this?

If I have to move the scrollbar programmatically when a new message is added, I would only want to do this if the current last message is display. This way if the user is looking at an old message I don't move it off the screen. How would this be done?

[526 byte] By [BaltimoreJohna] at [2007-10-2 10:23:00]
# 1
when you add the message, include thislist.ensureIndexIsVisible(dlm.size()-1);(where dlm is the DefaultListModel)
Michael_Dunna at 2007-7-13 1:55:30 > top of Java-index,Desktop,Core GUI APIs...
# 2

Here is solution for vertical scrollbar and JList, but maybe it works and for other components in JScrollPane.

JList list;

...

Rectangle rect = new Rectangle(0, 0, 0, 0);

rect.y = (int)list.getPreferredSize().getHeight();

list.scrollRectToVisible(rect);

ivanholuba at 2007-7-13 1:55:30 > top of Java-index,Desktop,Core GUI APIs...