我使用LWUIT创建了List 但是显示了带索引的项目 喜欢
我想删除左侧索引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 :(得分:6)
答案 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);