Rick-Rainer Ludwig
Rick-Rainer Ludwig

Reputation: 2401

Eclipse RCP: Add image to list

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

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 by:

listViewer.setLabelProvider(new MyListLabelProvider());

I do get the correct text, but no image. I am sure my label provider is used due to debugging the code and I can change the provided label text, too. I only do not see an image. The image is loaded and non-null.

What do I need to switch on to get the label shown? What do I miss here?

Upvotes: 3

Views: 1286

Answers (1)

Krumelur
Krumelur

Reputation: 32497

I am not sure the ListViewer is capable of displaying images. Try to switch to a single-column TableViewer and see if that helps.

Upvotes: 1

Related Questions