I have a ListViewer with a custom LabelProvider. The getText part works fine, but the getImage method of the LabelProvider never gets called.
I also tried to use a DecoratedLabelProvider but this did not work either.
class RadioLabelProvider extends LabelProvider{
Display d;
public RadioLabelProvider(Display d)
{
this.d = d;
}
@Override
public Image getImage(Object element)
{
Image image = d.getSystemImage(SWT.ICON_INFORMATION);
return image;
}
@Override
public String getText(Object element)
{
RadioElement re = (RadioElement) element;
return re.getIP();
}
}
Usage:
availableDevicesList = new ListViewer(this, SWT.SINGLE | SWT.BORDER);
availableDevicesList.setContentProvider(new ArrayContentProvider());
availableDevicesList.setLabelProvider(new RadioLabelProvider(getDisplay()));
availableDevicesList.setInput(devic开发者_Python百科es);
What am I doing wrong? Or does the ListViewer not support images? Thanks
I found out that on ListViewers getImage really wont get called.
Instead I used a TableViewer with a single column. Also the DecoratingLableProvider works so I can set the image depening on the objects status.
In the JFace source header comment of class ListViewer
you find that a ListViewer is
A concrete viewer based on an SWT
List
control.
and
Note that the SWT
List
control only supports the display of strings, not icons. If you need to show icons for items, useTableViewer
instead.
精彩评论