Eclipse RCP: Add Image to List

I want to add images to items in a list in Eclipse RCP. I provide a custom LabelProvider that looks like this:

package com.puresol;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

public class MyListLabelProvider extends LabelProvider {

    private final Image folderImage = PlatformUI.getWorkbench()
        .getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);

    @Override
    public void dispose() {
        folderImage.dispose();
    }

    @Override
    public String getText(Object element) {
        return element.toString();
    }

    @Override
        public Image getImage(Object element) {
        return folderImage;
    }
}

      

I add this label provider:

listViewer.setLabelProvider(new MyListLabelProvider());

      

I am getting correct text, but no image. I'm sure my shortcut provider is in use because of debugging the code, and I can change the provided shortcut text as well. I cannot see the image. Image loaded and not empty.

What do I need to include in order to show the shortcut? What am I missing here?

+3


source to share


1 answer


I'm not sure if I am ListViewer

capable of displaying images. Try switching one column TableViewer

and see if that helps.



+1


source







All Articles