i have titles and an images to be displayed on my LWUIT Form Screen from Rss File ,For this ,i have used ListCellRenderer,(i Referred this link http://lwuit.blogspot.in/2008/07/lwuit-list-renderer-by-chen-fishbein.html ) ,but the problem is,images and titles should be displayed on my Form screen side by side in a single line,but for some titles from Rss ,i am not able to display side by side,i am able to display image in one line and title will be in second line? here my code:
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;
}
The problem you have is that you placed both the name and icon label inside a container. You did not set the layout of the container. You dont have to use a container, but if you must set its layout. Put the image on the WEST or EAST of the BorderLayout and then put the container in the center.
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);