2011-05-17 74 views
0

我已經使用LWUIT創建列表。
但顯示我的項目與索引。
刪除lwuit列表中的索引

  1. 項目-1
  2. 項目-2
  3. 項目-3

我想刪除左側指數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); 



     } 
} 

謝謝。

+0

您可以發佈相關代碼 – 2011-05-17 13:28:24

+0

我已發佈我的代碼。 – Nirav 2011-05-17 13:39:52

回答

6

嘗試:

list.setListCellRenderer(new DefaultListCellRenderer(false)); 

javadocs解釋原因假 「showLineNumbers」

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