2012-08-28 89 views
1

我有標題和一個圖像顯示在我的LWUIT表格屏幕從Rss文件,爲此,我已經使用ListCellRenderer,(我推薦此鏈接http://lwuit.blogspot.in/2008/07/lwuit-list-renderer-by-chen-fishbein.html),但問題是,圖像和標題應該在一行中並排顯示在我的Form屏幕上,但對於Rss中的一些標題,我無法並排顯示,我可以在一行顯示圖像,標題將在第二行顯示? 這裏我的代碼:LWUIT表格標題從Rss

public class NewsListCellRenderer extends Container implements ListCellRenderer { 
    private Label name = new Label(""); 
    private Label icon = new Label(""); 
    private Label focus = new Label(""); 
    public NewsListCellRenderer() { 
    setLayout(new BorderLayout()); 
    Container cnt = new Container();  
    name.getStyle().setBgTransparency(0); 
    name.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL)); 
    cnt.addComponent(icon); 
    cnt.addComponent(name); 
    addComponent(BorderLayout.CENTER, cnt); 
    focus.getStyle().setBgTransparency(100); 
    focus.getStyle().setBgColor(0xFFFFFF); 
    } 
public Component getListCellRendererComponent(List list, Object value, int i, boolean bln) { 
    News news = (News) value; 
    name.setText(news.getTitle().trim()); 
    icon.setIcon(news.geImage()); 
    this.getStyle().setBorder(Border.createLineBorder(1, 0x666666));  
     return this; 
    } 

回答

2

你的問題是,你放在一個容器內的名稱和圖標標籤兩種。您沒有設置容器的佈局。您不必使用容器,但是如果您必須設置其佈局。將圖像放在BorderLayout的WEST或EAST上,然後將容器放在中間。

setLayout(new BorderLayout()); 

Container cnt = new Container(); 
cnt.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); 

name.getStyle().setBgTransparency(0); 
name.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL)); 

cnt.addComponent(name); 

addComponent(BorderLayout.WEST, icon); 
addComponent(BorderLayout.CENTER, cnt);