views:

29

answers:

1

As from subject, I have an awt.List object. When I add something to the list I would like to scroll it down to show the last inserted object.

For instance:

myList.add("sometext");
myList.select(myList.getItemCount()-1);
myList.showSelectedItem(); // Or something like that

The documentation does not seem to list any method that does something like that, can anybody help please?

+1  A: 

I am not sure that this is possible (explicitly). In my experience I have written an app for a Windows Mobile device using AWT and when I used one JVM calling myList.select(myList.getItemCount()-1); was enough to get it to scroll to that item, but as soon as I switched to another JVM it did not do it. So it is implementation dependent but I think there is no requirement in the specification that says that a List field should do this.

My workaround was simply to reverse the List, so that new items were added at the top. Understandably this is not ideal for all situtations, but in my case it was fine.

DaveJohnston
Thank you, I feared the answer would sound like that... :(I'll just have to use your workaround.
nico