I’m having trouble with a listBox control, being unable to select any items in it - no visual cue, no callback, just the list of items displayed.
Here’s my xml:
[xml]<control name=“listBox” id=“groups_list” width=“100%” height=""
vertical=“on” horizontal=“off” displayItems=“15” selection=“Single”
viewConverterClass=“com.limewoodGames.holicity.client.gui.community.GroupViewConverter”>
<control name=“group-list-item”/>
</control>[/xml]
The group-list-item definition:
[xml]<controlDefinition name=“group-list-item”>
<panel childLayout=“horizontal” width=“100%” align=“center”>
<image id="#group-icon" width=“20px” height=“20px” />
<control name=“label” id="#group-name" font=“Interface/Fonts/freesans-12.fnt” align=“left”
textHAlign=“left” wrap=“true” height=“20px” width="" />
</panel>
</controlDefinition>[/xml]
The GroupViewConverter:
[java]public class GroupViewConverter implements ListBoxViewConverter<CGroup> {
private static final String GROUP_ICON = “#group-icon”;
private static final String GROUP_NAME = “#group-name”;
/**
- Default constructor.
*/
public GroupViewConverter() {
}
/**
- {@inheritDoc}
*/
@Override
public final void display(final Element listBoxItem, final CGroup item) {
final Element text = listBoxItem.findElementByName(GROUP_NAME);
final TextRenderer textRenderer = text.getRenderer(TextRenderer.class);
final Element icon = listBoxItem.findElementByName(GROUP_ICON);
final ImageRenderer iconRenderer = icon.getRenderer(ImageRenderer.class);
if (item != null) {
textRenderer.setText(item.getName());
iconRenderer.setImage(item.getIcon());
} else {
textRenderer.setText("");
iconRenderer.setImage(null);
}
}
/**
- {@inheritDoc}
*/
@Override
public final int getWidth(final Element listBoxItem, final CGroup item) {
final Element text = listBoxItem.findElementByName(GROUP_NAME);
final TextRenderer textRenderer = text.getRenderer(TextRenderer.class);
return ((textRenderer.getFont() == null) ? 0 : textRenderer.getFont().getWidth(item.getName()))
- ((item.getIcon() == null) ? 0 : item.getIcon().getWidth());
}
}[/java]
The list displays great and you can add items without a problem, but there’s no selection at all.
Do you have to do something else to enable selection in a listBox or did I use it in an incorrect way?