简体   繁体   English

向下滚动awt.List

[英]Scrolling down an awt.List

As from subject, I have an awt.List object. 从主题awt.List ,我有一个awt.List对象。 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? 文档似乎没有列出执行此类操作的任何方法,请问有人可以帮忙吗?

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); 以我的经验,我使用AWT为Windows Mobile设备编写了一个应用程序,当我使用一个JVM调用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. 足以使其滚动到该项目,但是当我切换到另一个JVM时,它并没有这样做。 So it is implementation dependent but I think there is no requirement in the specification that says that a List field should do this. 因此,它取决于实现,但是我认为规范中没有要求说List字段应该执行此操作。

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. 我使用makeVisible(index)调用,其中index是所选项目的索引。 This scrolls the listbox down until the selected item is visible. 这将向下滚动列表框,直到可见所选项目。 I'm using JDK 1.6.0_65 on Mac OSX 10.8. 我在Mac OSX 10.8上使用JDK 1.6.0_65。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM