1

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();
Mun0n
  • 4,438
  • 4
  • 28
  • 46
Jugal Inani
  • 133
  • 1
  • 17

1 Answers1

5

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.

Demian Kasier
  • 2,475
  • 6
  • 30
  • 40
  • 1
    This is a good approach and it works really well for all versions of LWUIT. LWUIT 1.5 introduced the GenericListCellRenderer which is designed for the GUI builder where you can visually design a check box list renderer. See the Tzone Friends demo from the 1.5 distribution, when you add a new friend you would see a checkbox list that was created with the GUI builder. – Shai Almog Oct 09 '11 at 08:20