向列表中的每个列表项添加图标
我想为列表和图像中的每个项目添加一个图标。这是我创建列表的代码:
Form f3=new Form("DEMO FORM");
f3.setScrollable(true);
f3.setLayout(new BorderLayout());
f3.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
String items[] = {"one","two","three","four"};
DefaultListModel myListModel = new DefaultListModel(items);
List lst=new List(myListModel);
f3.addComponent(lst);
f3.show();
我该怎么做?
I want to add an icon to each items in a list an image. This is my code for creating list :
Form f3=new Form("DEMO FORM");
f3.setScrollable(true);
f3.setLayout(new BorderLayout());
f3.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
String items[] = {"one","two","three","four"};
DefaultListModel myListModel = new DefaultListModel(items);
List lst=new List(myListModel);
f3.addComponent(lst);
f3.show();
How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用此列表渲染器
您可以从此渲染器中删除不需要的装饰:焦点上的颜色变化等,...我还为未选定和选定的列表项提供了两个不同图标的代码。
然后像这样设置列表的渲染器:
Use this List Renderer
You can remove unwanted embelishments from this renderer: color changes on focus, etc, ...I have also given code for two different icons for the unselected and selected list item.
Then set the renderer of the list like this:
您需要将图像数据放入模型中或为渲染器提供某种方式来提取和应用该数据。请参阅 LWUIT 演示中的示例,其中有渲染器演示或滚动演示,其中显示了包含图标和各种条目布局的列表。
You need to place the image data in the model or provide some way for the renderer to extract and apply that data. See samples for this in the LWUIT demo where you have both the renderer demo or the Scrolling demo which show off lists that have icons and various entry layouts.
我使用了较新的“通用列表单元格渲染器”来生成列表中的缩略图(图标)。我发现它比其他列表渲染选项更容易实现。以下链接包含示例代码,展示如何使用此技术创建列表。
http://codenameone.blogspot.in/2011 /03/list-rendering-easy-way-generic-list.html
为了显示缩略图,我做了以下操作,这几乎是 LWUIT 中的锅炉。
I have used newer 'Generic List Cell Renderer' to produce thumbnail(icons) in a list. I found it easier to implement than other options for list rendering. Following link has example code to show how to create list using this technique.
http://codenameone.blogspot.in/2011/03/list-rendering-easy-way-generic-list.html
To show thumbnail i did the following which is pretty much boilerplace in LWUIT.