删除lwuit列表中的索引

时间:2011-05-17 13:08:15

标签: java java-me lwuit

我使用LWUIT创建了List 但是显示了带索引的项目 喜欢

  1. item-1
  2. item-2
  3. item-3
  4. 我想删除左侧索引1,2,3我该怎么做?

    代码:

     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);
    
    
    
            }
    }
    

    谢谢。

2 个答案:

答案 0 :(得分:6)

尝试:

list.setListCellRenderer(new DefaultListCellRenderer(false));

javadocs解释了错误“showLineNumbers”的原因

答案 1 :(得分:1)

试试这个 -

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;
    }
}

和 -

    List list = new List(listModel);
    RemoveIndexRenderer listCellRenderer = new RemoveIndexRenderer();
    list.setListCellRenderer(listCellRenderer);