Reputation: 1391
I would like to add a image to a button in my table. The table is displayed in my main GUI. I am using a TableViewer
to display the table.
private void createTableViewer(Composite parent) {
viewer = new AplotDataTableViewer(parent, SWT.BORDER|SWT.V_SCROLL|SWT.FULL_SELECTION);
viewer.setInput(AplotDataModel.getInstance().getArrayData());
}
AplotDataTableViewer
is a separate class. The constructor for AplotDataTableViewer
takes in the composite and Style.
So when I try to add a image in the AplotDataTableViewer
class, it gives me a error on the Display
variable. I think it is because Image requires a Display.
Image image = new Image(display, String);
I am not sure what it is needing for display? If it is needing the display from the main GUI, how do I get that?
Upvotes: 0
Views: 746
Reputation: 3085
I am not sure what error you are getting. I am guessing it might be "Invalid Thread access" as you are accessing UI objects from non-UI thread.
You can create images by referring to the link given by Baz. If your plugin has Activator, just check for public static ImageDescriptor getImageDescriptor(String path)
here path starts with ex: /icons/image.png. User ImageDescriptor.createImage(true)
will give the actual image that you are looking for. Keep track of the images in a cache before creating new one from imagedescriptor.
Setting Image on Button, check for documentation. Few platforms won't support setting both image and text.
Upvotes: 0
Reputation: 36884
You can just use:
Image image = new Image(Display.getDefault(), "path/to/image.png");
Or use Display.getCurrent()
instead.
For more details, here is a good tutorial about SWT Image
s:
Upvotes: 1