LWUIT表格包含多个组件

时间:2012-10-10 11:31:20

标签: java-me lwuit

我已经逐个添加了多个组件到我的LWUIT表单,但问题是我无法逐个显示这些添加的组件,就像我在代码中添加的一样,我能够显示日期和我的图像在单行上(并排)有时候标题和日期在一行上,我从Rss文件中获取详细信息。 如何在我的代码中逐一显示那些组件,而不是一行中添加2个组件?

感谢....

这是我的代码:

 Label pubDate = new Label(detailNews.getPubDate().substring(0, 16));
        Label title=new Label();
        title.setText(detailNews.getTitle());
        title.startTicker();
        pubDate.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
            Image geImage = detailNews.geImage(); 
        Label icon=new Label(geImage);
                form2.addComponent(title);
                form2.addComponent(pubDate);
        textarea.setText(detailNews.getDescription());
        textarea.requestFocus();
      form2.addComponent(icon);
       form2.addComponent(textarea);
        form2.show();

1 个答案:

答案 0 :(得分:2)

我的想法是:

您可以使用BoxLayoutY创建Container,并将此TextArea和图标添加到Container。接下来,将此Container添加到Form。类似的东西:

       Label pubDate = new Label(detailNews.getPubDate().substring(0, 16));
        Label title=new Label();
        title.setText(detailNews.getTitle());
        title.startTicker();
        pubDate.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
            Image geImage = detailNews.geImage(); 
        Label icon=new Label(geImage);

        Container container = new Container(new BoxLayout(BoxLAyout.Y_AXIS));
        container.addComponent(title);
        container.addComponent(pubDate);
        container.addComponent(icon);
        container.addComponent(textarea);
        form2.addComponent(container);

        textarea.setText(detailNews.getDescription());
        textarea.requestFocus();
        form2.show();
相关问题