Skip to main content

Alternating background color in a list

3 replies [Last post]
ghady_rayess
Offline
Joined: 2009-01-09
Points: 0

hello,
I'm trying to display a list of Labels with alternating background color.
The ListCellRenderer is very simple and looks like this:

private class AltRenderer implements ListCellRenderer {
public Component getListCellRendererComponent(List list, Object evnt, int index, boolean isSelected) {
return (Label)evnt;
}
public Component getListFocusComponent(List list) {
return null;
}
}
}

I have a form that adds 10 Labels to the list where each Label alternates its background color:


Form form = new Form();
Form form = new Form();
form.setLayout(new BorderLayout());
List list = new List();
list.setListCellRenderer(new ChatRenderer());
boolean alter = true;
for(int x = 0; x < 30; x++){
Label l = new Label("Hello "+x);
l.getStyle().setBgTransparency(255);
if(alter){
l.getStyle().setBgColor(0x00ff0000);
}else{
l.getStyle().setBgColor(0x000000ff);
}
alter = !alter;
list.addItem(l);
}
form.addComponent(BorderLayout.CENTER, list);
form.show();

Instead of Red and Blue backgrounds, i'm getting all the background color of the Labels to be Red.

Any ideas?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ghady_rayess
Offline
Joined: 2009-01-09
Points: 0

I believe there is a bug there.
If u set the FgColor instead of the BgColor, the List will show alternating Fg colors.

Can anybody confirms this.

Chen Fishbein

Hi,
Try this List.setMutableRendererBackgrounds(true)

Regards,
Chen

lwuit-users@mobileandembedded.org wrote:
> I believe there is a bug there.
> If u set the FgColor instead of the BgColor, the List will show alternating Fg colors.
>
> Can anybody confirms this.
> [Message sent by forum member 'ghady_rayess' (ghady_rayess@yahoo.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=366019
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

ghady_rayess
Offline
Joined: 2009-01-09
Points: 0

ok it works.
Thanx Chen