来自Rss的LWUIT表格标题

时间:2012-08-28 10:33:47

标签: java-me rss lwuit

我有从Rss文件在我的LWUIT表格屏幕上显示的标题和图像,为此,我使用了ListCellRenderer,(我推荐此链接http://lwuit.blogspot.in/2008/07/lwuit-list-renderer-by-chen-fishbein.html),但问题是,图像和标题应该在我的表单屏幕上并排显示在单行中,但对于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;
    }

1 个答案:

答案 0 :(得分: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);