List with checkbox using LWUIT

前提是你 提交于 2019-12-01 11:52:45

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.

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