Reputation: 5760
I have created List using LWUIT.
but is shows me item with index.
like
I want to remove left side index 1,2,3 how can I do that?
Code:
class mainForm extends Form implements ActionListener{
List list;
String newkey = "";
final String COMPANY[] = {"AIRCEL", "AIRTEL", "BPL", "BSNL", "IDEA", "RELIANCE", "TATA DOCOMO", "TATA INDICOM", "UNINOR", "VIRGIN", "VIDEOCON", "VODAFONE", "AIRCEL1", "AIRTEL2", "BPL1", "BSNL1", "IDEA1", "RELIANCE1", "TATA DOCOMO1", "TATA INDICOM1", "UNINOR1", "VIRGIN1", "VIDEOCON1"};
final int CO_LENGTH = COMPANY.length;
mainForm() {
super("Main Form");
setLayout(new BoxLayout(BoxLayout.Y_AXIS));
list = new List(COMPANY);
list.addActionListener(this);
list.setPreferredW(getWidth());
addComponent(list);
}
}
Thank you.
Upvotes: 0
Views: 1004
Reputation: 52770
Try:
list.setListCellRenderer(new DefaultListCellRenderer(false));
The javadocs explains the reason for false "showLineNumbers"
Upvotes: 6
Reputation: 26
Try this one -
private static class RemoveIndexRenderer extends Label implements ListCellRenderer {
public RemoveIndexRenderer() {
super("");
}
public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
setText(value.toString());
setFocus(isSelected);
getStyle().setBgTransparency(100);
return this;
}
public Component getListFocusComponent(List list) {
setText("");
setFocus(true);
getStyle().setBgTransparency(100);
return this;
}
}
And -
List list = new List(listModel);
RemoveIndexRenderer listCellRenderer = new RemoveIndexRenderer();
list.setListCellRenderer(listCellRenderer);
Upvotes: 1