开发者

Scrolling down an awt.List

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 t开发者_C百科hat does something like that, can anybody help please?


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.


I use the makeVisible(index) call where index is the index of the item that is selected. This scrolls the listbox down until the selected item is visible. I'm using JDK 1.6.0_65 on Mac OSX 10.8.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜