List with checkbox using LWUIT

我与影子孤独终老i 提交于 2019-12-30 13:00:20

问题


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();

回答1:


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: 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: has a label for the string and the image of the checkitem it extends Container and implements ListCellRenderer

CHECKITEMMODEL: this extends the defaultlistmodel. it has methods to get the checkeditems and setthem checked or unchecked.

to recap:

  • set the correct items in the vector
  • set the correct renderer
  • set the correct model

and to use it add an actionlistener or it will al be for nothing.



来源:https://stackoverflow.com/questions/2810630/list-with-checkbox-using-lwuit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!