Nirav
Nirav

Reputation: 5760

Remove Index in lwuit list

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.

Upvotes: 0

Views: 1004

Answers (2)

Shai Almog
Shai Almog

Reputation: 52770

Try:

list.setListCellRenderer(new DefaultListCellRenderer(false));

The javadocs explains the reason for false "showLineNumbers"

Upvotes: 6

Payal
Payal

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

Related Questions