LWUIT扩展之list Renderer

 1. model

 

class Contact { private String name; private String email; private Image pic; public Contact(String name, String email, Image pic) { this.name = name; this.email = email; this.pic = pic; } public String getName() { return name; } public String getEmail() { return email; } public Image getPic() { return pic; } }

 

2. render

 

class ContactsRenderer extends Container implements ListCellRenderer { private Label name = new Label(""); private Label email = new Label(""); private Label pic = new Label(""); private Label focus = new Label(""); // sean 建筑展示构架 public ContactsRenderer() { setLayout(new BorderLayout()); addComponent(BorderLayout.WEST, pic); Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS)); name.getStyle().setBgTransparency(0); //name.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM)); email.getStyle().setBgTransparency(0); cnt.addComponent(name); cnt.addComponent(email); addComponent(BorderLayout.CENTER, cnt); //focus.getStyle().setBgTransparency(100); } // sean 为每一个实例的展示构架填充展示内容 public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) { Contact person = (Contact) value; name.setText(person.getName()); email.setText(person.getEmail()); pic.setIcon(person.getPic()); return this; } // sean 当前选中实例,显示动画的起始画面 public Component getListFocusComponent(List list) { return focus; } }

 

 

你可能感兴趣的:(list,String,object,image,扩展,email)