问题描述
我正在使用LWUIT获得List
中可供选择的搜索工具.现在我想知道如何使用CheckBoxes
显示列表?
I am using LWUIT for getting a search facility for selection in the List
.Now I want to know how can I display the list with CheckBoxes
?
list=new List(vector);
cform.addComponent(list);
cform.addComponent(t);
cform.show();
推荐答案
我不知道有没有比我的解决方案更简单的解决方案,但是我的是高度可定制的并且可以用于很多目的.
I don't know if there is a more simple solution then mine, but mine is highly customizable and can serve for a lot of purposes.
List l = new List;
Vector v = new Vector();
for(int i = 0; i < 10; ++i){
v.addElement(new CheckItem("itemtekst"));
}
l.setListCellRenderer(new CheckItemRenderer());
l.setModel(new CheckItemModel(v));
上面的代码使其起作用.如您所料,您必须创建一个新类并重写两个类才能使其正常工作.
the code above makes it work. As you can guess you have to make a new class and override two to make it work.
CHECKITEM:此类具有一个字符串和一个图像.以及设置者和获取者.它也有一个布尔值,显示是否选中它.
CHECKITEM: this class has a string and an image. as well as setters and getters. it also has a boolean that shows if it is checked or not.
CHECKITEMRENDERER:具有字符串标签和扩展了Container并实现ListCellRenderer的checkitem图像
CHECKITEMRENDERER: has a label for the string and the image of the checkitem it extends Container and implements ListCellRenderer
CHECKITEMMODEL:这扩展了默认列表模型.它具有获取选中项和设置选中或未选中项的方法.
CHECKITEMMODEL: this extends the defaultlistmodel. it has methods to get the checkeditems and setthem checked or unchecked.
回顾:
- 在向量中设置正确的项目
- 设置正确的渲染器
- 设置正确的模型
并使用它添加一个动作侦听器,否则将一无所获.
and to use it add an actionlistener or it will al be for nothing.
这篇关于使用LWUIT列出带有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!