0

I have created List using LWUIT.
but is shows me item with index.
like

  1. item-1
  2. item-2
  3. item-3

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.

Nirav
  • 5,700
  • 4
  • 34
  • 44

2 Answers2

6

Try:

list.setListCellRenderer(new DefaultListCellRenderer(false));

The javadocs explains the reason for false "showLineNumbers"

drubin
  • 1,012
  • 7
  • 10
Shai Almog
  • 51,749
  • 5
  • 35
  • 65
1

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);
Payal
  • 26
  • 2