JList SetSelectedIndex doesn't scroll to index's position

Hi.

My program simulates a microprocessor and it has memory locations and a list of instructions. As the user clicks the button to execute the next instruction, I have it so the next instruction to be executed is highlighted using JList's setSelectedIndex(index) method. Unfortunately, this simply highlights the line in the list that is at the index. Since my lists can be very large, it's cumbersome to have to scroll down to find the highlighted instruction or memory location. Is there a way to have the scroll pane move according to the location of the selected item?

Thanks!

[601 byte] By [tk393a] at [2007-11-27 4:30:09]
# 1

i think it's not a good way but since nobody answered, you can still try something like that:

// new selection in the jlist

JScrollBar bar = scrollPaneOfTheList.getVerticalScrollBar();

bar.setValue(sizeOfACellOfTheList * indexOfNewCellSelected);

i'm really not sure if it works, just give it a try :)

calvino_inda at 2007-7-12 9:39:21 > top of Java-index,Java Essentials,Java Programming...
# 2
ensureIndexIsVisible(int index); Scrolls the viewport to make the specified cell completely visible.
watertownjordana at 2007-7-12 9:39:21 > top of Java-index,Java Essentials,Java Programming...
# 3

> ensureIndexIsVisible(int index);

>

> Scrolls the viewport to make the specified

> cell completely visible.

BEAUTIFUL! exactly what i was looking for, thanks so much! i have to present this project in less than 2 hours and this just made it so much better.

tk393a at 2007-7-12 9:39:21 > top of Java-index,Java Essentials,Java Programming...