Scroll JList to bottom automatic .  
Author Message
Jonny





PostPosted: 2005-10-6 3:06:00 Top

java-programmer, Scroll JList to bottom automatic .
Hi,

How to automatic scroll a JList to bottom of the list, i.e when inserting
new elements. My list have i created like this:

JList jlist = new JList(objectArray);
JScrollPane scroll = new JList(jlist);

Any simple code to do this?

Best Regards
/Jonny
 
Roland





PostPosted: 2005-10-6 4:26:00 Top

java-programmer >> Scroll JList to bottom automatic . On 5-10-2005 21:06, Jonny wrote:
> Hi,
>
> How to automatic scroll a JList to bottom of the list, i.e when inserting
> new elements. My list have i created like this:
>
> JList jlist = new JList(objectArray);
> JScrollPane scroll = new JList(jlist);
>
> Any simple code to do this?
>
> Best Regards
> /Jonny

<http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JList.html#ensureIndexIsVisible(int)>

int lastIndex = jlist.getModel().getSize() - 1;
if (lastIndex >= 0) {
jlist.ensureIndexIsVisible(lastIndex);
}


--
Regards,

Roland de Ruiter
` ___ ___
`/__/ w_/ /__/
/ \ /_/ / \