Skip to main content

ListCellRenderer bgColour

6 replies [Last post]
robovanbasten
Offline
Joined: 2008-12-19

Hi All,
I'm using LWUIT v1.3 to display a List (ListCellRenderer).
My list contains a number of MyItems (a custom Object), one of the properties of MyItem is Colour (i.e. MyItem.getColour()).

I'm trying to set the bgColour's of the item's in my list using getColour but it doesn't seem to work. I had this sorted but after updating to the latest LWUIT it stopped working correctly. Any help much appreciated, code:

public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
MyItem item = (MyItem)value;
setText(item.getName());
setFocus(isSelected);
if (isSelected) {
getStyle().setBorder(Border.getDefaultBorder());
getStyle().setFont(m_selectedFont);
} else {
getStyle().setBorder(null);
getStyle().setFont(m_unselectedFont);
}

getUnselectedStyle().setBgColor(item.getColour());
getSelectedStyle().setBgColor(item.getColour());

return this;
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
robovanbasten
Offline
Joined: 2008-12-19

bump.

Anyone got any ideas?

What I'm trying to do is have a list of items (MyItem's) where I can (at run-time) change the background colour (using MyItem.getColour()). My selected (or focused) item is identified by a border. I used to use...

getStyle().setBgSelectionColor(MyIten.getColour());

... but this has been deprecated in LWUIT 1.3

benefiz
Offline
Joined: 2008-10-29

robovanbasten wrote:
bump. Anyone got any ideas? What I'm trying to do is have a list of items (MyItem's) where I can (at run-time) change the background colour (using MyItem.getColour()). My selected (or focused) item is identified by a border. I used to use... getStyle().setBgSelectionColor(MyIten.getColour()); ... but this has been deprecated in LWUIT 1.3

I was just stumbling about the same problem and wondering if this was solved somehow? Trying to have list items with different backgrounds. I already tried to return different components (e.g. like in fisheye) but this also does not work! The first item set the background color for all others! Are the items all sharing the same style? Like they share the same height?

Ben

vprise
Offline
Joined: 2003-11-07

Please open new threads for completely unrelated issues.

Use List.setMutableRendererBackgrounds(true) to disable a list optimization we have in place for item background rendering.

benefiz
Offline
Joined: 2008-10-29

Hey vprise,

actually the issue was totally related to the thread opener and i prefer to re-open old threads with an already existing topic. But i was additionally providing other workarounds, which didnt work out either :)

Anyway, thanks for the hint! That solved it for me and probably for the thread opener, too (if he still cares).

Thanks

Ben

ronanoc
Offline
Joined: 2007-10-29

Are you sure item.getColour() is returning a value?

robovanbasten
Offline
Joined: 2008-12-19

Yep defo a value there.