I am placing image in a column depending on the status of a boolean value.
col = new TableViewerColumn(this, SWT.NONE);
col.getColumn().setWidth(70);
col.getColumn().setText("Print Status");
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
if (((AplotResultsDataModel.ResultsData) element).isSuccess()) {
return SUCCESS;
}
return FAIL;
}
});
Here is the getImage method
private static Image getImage(String file) {
Bundle bundle = FrameworkUtil.getBundle(Viewer.class);
URL url = FileLocator.find(bundle, new Path("icons/" + file), null);
ImageDescriptor image = ImageDescriptor.createFromURL(url);
return image.createImage();
}
I have tried two ways of creating the image.
private static final Image FAIL = getImage("failed.png");
And
final Image FAIL = new Image(Display.getDefault() ,"D:/Users/workspace/com.aplot/icons/failed.png");
In both cases the image does display but there is a text path beside it. The path looks like it is the array value for that column.
EXAMPLE:
[image] com.aplot.datamodel.ResultsDataModel$ResultsData@9cce9
How can I remove the text and only show the image?
Override
getText()method inColumnLabelProviderand return empty string. if you dont override, it is always display element.toString(). thats why you see toString() value of your data object there.