javaswt

Creating a button with swt.arrow and image


I'd like to create a button like the one represented in the figure enter image description here to my Eclipse RCP applications editor part. Currently I can only have one of the images (add or arrow). Is there some easy way to have both of the images in one button?

public void createPartControl(Composite parent) {
    ...
    Button btn = new Button(btnCntrl, SWT.FLAT|SWT.ARROW|SWT.DOWN);
    btn.setImage(Activator.getImageDescriptor("platform:/plugin/com.famfamfam.silk/icons/add.png").createImage());
    ...
}

Solution

  • The SWT Button can only have either an arrow or text and/or image. To emulate an image button with a drop-down arrow you may want to use a toolbar with a tool button.

    For Example:

    ToolBar toolbar = new ToolBar( parent, SWT.NONE );
    ToolItem button = new ToolItem( toolBar, SWT.DROP_DOWN );
    button.setImage( ... );