Setting viewable portion of viewport or location of a ScrollBar

I'm using several JLists and JTextPanes in JScrollPanes...is there a way to set the location of each component's vertical scrollbar so that information at the bottom of the viewport is visible and a user must scroll up to see the rest of the information? Or rather, a way to set what part of the viewport is being shown first?I have the requirement to add new items to the bottom of my lists/text dialogs, but must also have the most recent items being shown as default.

Thanks.

[500 byte] By [virelay] at [2007-9-26 4:21:13]
# 1

The viewport that the scrollpane holds provides a method "scrollRectToVisible(Rectangle rect)". You can use this to adjust the scrollbars as needed. In your case, if you want the last added item in the list to be visible, you would essentially get the rect coordinates of the last item and pass the rect over to the method mentioned above.

Here is a sample:

Rectangle rect = list.getCellBounds(list.getModel().getSize() - 1, list.getModel().getSize());

scrollPane.getViewPort().scrollRectToVisible(rect);

Hope that helps.

Regards,

Vijay

vijayreddy at 2007-6-29 17:25:11 > top of Java-index,Archived Forums,Swing...
# 2
Thanks!
virelay at 2007-6-29 17:25:11 > top of Java-index,Archived Forums,Swing...