Java Code Examples for org.eclipse.swt.widgets.Button#setBackground()
The following examples show how to use
org.eclipse.swt.widgets.Button#setBackground() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnterOptionsDialog.java From hop with Apache License 2.0 | 6 votes |
/** * Setting the layout of a <i>Reset</i> option button. Either a button image is set - if existing - or a text. * * @param button The button */ private FormData layoutResetOptionButton( Button button ) { FormData fd = new FormData(); Image editButton = GuiResource.getInstance().getResetOptionButton(); if ( editButton != null ) { button.setImage( editButton ); button.setBackground( GuiResource.getInstance().getColorWhite() ); fd.width = editButton.getBounds().width + 20; fd.height = editButton.getBounds().height; } else { button.setText( BaseMessages.getString( PKG, "EnterOptionsDialog.Button.Reset" ) ); } button.setToolTipText( BaseMessages.getString( PKG, "EnterOptionsDialog.Button.Reset.Tooltip" ) ); return fd; }
Example 2
Source File: EnterOptionsDialog.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * Setting the layout of an <i>Edit</i> option button. Either a button image is set - if existing - or a text. * * @param button * The button */ private FormData layoutEditOptionButton( Button button ) { FormData fd = new FormData(); Image editButton = GUIResource.getInstance().getEditOptionButton(); if ( editButton != null ) { button.setImage( editButton ); button.setBackground( GUIResource.getInstance().getColorWhite() ); fd.width = editButton.getBounds().width + 20; fd.height = editButton.getBounds().height; } else { button.setText( BaseMessages.getString( PKG, "EnterOptionsDialog.Button.Edit" ) ); } button.setToolTipText( BaseMessages.getString( PKG, "EnterOptionsDialog.Button.Edit.Tooltip" ) ); return fd; }
Example 3
Source File: EnterOptionsDialog.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * Setting the layout of a <i>Reset</i> option button. Either a button image is set - if existing - or a text. * * @param button * The button */ private FormData layoutResetOptionButton( Button button ) { FormData fd = new FormData(); Image editButton = GUIResource.getInstance().getResetOptionButton(); if ( editButton != null ) { button.setImage( editButton ); button.setBackground( GUIResource.getInstance().getColorWhite() ); fd.width = editButton.getBounds().width + 20; fd.height = editButton.getBounds().height; } else { button.setText( BaseMessages.getString( PKG, "EnterOptionsDialog.Button.Reset" ) ); } button.setToolTipText( BaseMessages.getString( PKG, "EnterOptionsDialog.Button.Reset.Tooltip" ) ); return fd; }
Example 4
Source File: BasePanel.java From nebula with Eclipse Public License 2.0 | 6 votes |
protected void createCommonPart(final Group group) { final Color white = group.getDisplay().getSystemColor(SWT.COLOR_WHITE); createLeftLabel(group, "Circle size"); circleSize = createTextWidget(group, 100); createConstraintsLabel(group, "(<1000)"); createLeftLabel(group, "Thickness"); thickness = createTextWidget(group, 10); createConstraintsLabel(group, "(1-50)"); createLeftLabel(group, "Show text"); checkbox = new Button(group, SWT.CHECK); final GridData gd = new GridData(GridData.FILL, GridData.CENTER, false, false); checkbox.setLayoutData(gd); checkbox.setBackground(white); checkbox.setSelection(true); new Label(group, SWT.NONE); }
Example 5
Source File: VButtonImageBak.java From nebula with Eclipse Public License 2.0 | 5 votes |
private void createImage(VButton button) { String key = getKey(button); if(requests.containsKey(key)) { requests.get(key).add(button); } else { requests.put(key, new ArrayList<VButton>()); requests.get(key).add(button); int style = button.getStyle() & (SWT.CHECK | SWT.RADIO); if(style == 0) { style = SWT.TOGGLE; // defaults to, and converts PUSH buttons to, TOGGLE } Button b = new Button(button.composite, style); b.setBackground(button.getBackground()); b.setBounds(button.getBounds()); if(button.hasState(VControl.STATE_SELECTED)) { b.setSelection(true); } if(button == VTracker.getFocusControl()) { b.setFocus(); } b.addListener(SWT.Paint, new ImageListener(key, b)); b.redraw(); b.update(); } }
Example 6
Source File: FooterArea.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Create a check box * * @param numberOfColumns */ private void createCheckBox(final int numberOfColumns) { final Button button = new Button(composite, SWT.CHECK); button.setText(checkBoxLabel); button.setSelection(checkBoxValue); button.setBackground(getGreyColor()); button.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false, numberOfColumns, 1)); button.addListener(SWT.Selection, e -> { checkBoxValue = button.getSelection(); }); }
Example 7
Source File: HorizontalSpinner.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Create minus button * * @param buttonStyle button style */ private void createMinusButton(final int buttonStyle) { leftButton = new Button(this, buttonStyle | SWT.LEFT); leftButton.setFont(getFont()); leftButton.setBackground(getBackground()); leftButton.setCursor(getCursor()); leftButton.setEnabled(getEnabled()); leftButton.setFont(getFont()); leftButton.setForeground(getForeground()); leftButton.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false, false)); }
Example 8
Source File: HorizontalSpinner.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Create plus button * * @param buttonStyle button style */ private void createPlusButton(final int buttonStyle) { rightButton = new Button(this, buttonStyle | SWT.RIGHT); rightButton.setFont(getFont()); rightButton.setBackground(getBackground()); rightButton.setCursor(getCursor()); rightButton.setEnabled(getEnabled()); rightButton.setFont(getFont()); rightButton.setForeground(getForeground()); rightButton.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false, false)); }
Example 9
Source File: PageSettingDialog.java From ermaster-b with Apache License 2.0 | 5 votes |
private void initDirectionGroup(Composite parent) { GridData gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = GridData.FILL; Group directionGroup = new Group(parent, SWT.NONE); directionGroup.setLayoutData(gridData); directionGroup.setBackground(ColorConstants.white); directionGroup.setText(ResourceString .getResourceString("label.page.direction")); GridLayout directionGroupLayout = new GridLayout(); directionGroupLayout.marginWidth = 20; directionGroupLayout.horizontalSpacing = 20; directionGroupLayout.numColumns = 4; directionGroup.setLayout(directionGroupLayout); Label vImage = new Label(directionGroup, SWT.NONE); vImage.setImage(Activator.getImage(ImageKey.PAGE_SETTING_V)); vButton = new Button(directionGroup, SWT.RADIO); vButton.setBackground(ColorConstants.white); vButton.setText(ResourceString.getResourceString("label.page.direction.v")); Label hImage = new Label(directionGroup, SWT.NONE); hImage.setImage(Activator.getImage(ImageKey.PAGE_SETTING_H)); hButton = new Button(directionGroup, SWT.RADIO); hButton.setBackground(ColorConstants.white); hButton.setText(ResourceString.getResourceString("label.page.direction.h")); }
Example 10
Source File: PageSettingDialog.java From erflute with Apache License 2.0 | 5 votes |
private void initDirectionGroup(Composite parent) { final GridData gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = GridData.FILL; final Group directionGroup = new Group(parent, SWT.NONE); directionGroup.setLayoutData(gridData); directionGroup.setBackground(ColorConstants.white); directionGroup.setText(DisplayMessages.getMessage("label.page.direction")); final GridLayout directionGroupLayout = new GridLayout(); directionGroupLayout.marginWidth = 20; directionGroupLayout.horizontalSpacing = 20; directionGroupLayout.numColumns = 4; directionGroup.setLayout(directionGroupLayout); final Label vImage = new Label(directionGroup, SWT.NONE); vImage.setImage(Activator.getImage(ImageKey.PAGE_SETTING_V)); vButton = new Button(directionGroup, SWT.RADIO); vButton.setBackground(ColorConstants.white); vButton.setText(DisplayMessages.getMessage("label.page.direction.v")); final Label hImage = new Label(directionGroup, SWT.NONE); hImage.setImage(Activator.getImage(ImageKey.PAGE_SETTING_H)); hButton = new Button(directionGroup, SWT.RADIO); hButton.setBackground(ColorConstants.white); hButton.setText(DisplayMessages.getMessage("label.page.direction.h")); }
Example 11
Source File: ClassFileEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private Button createButton(Composite parent, String text) { Button button = new Button(parent, SWT.FLAT); button.setBackground(fBackgroundColor); button.setForeground(fForegroundColor); if (text != null) button.setText(text); return button; }
Example 12
Source File: XSPEditorUtil.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
/** * this method will create a new Button on the given composite, with the given style and text. * @param aComposite * @param aStyle * @param aLabel * @return DCCommandButton */ static public Button createButton(Composite aComposite, int aStyle, String aLabel) { Button button = new Button(aComposite, aStyle); button.setBackground(aComposite.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); button.setText(aLabel); button.setEnabled(true); return button; }
Example 13
Source File: TransPerfDelegate.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Tell the user that the transformation is not running or that there is no monitoring configured. */ private void showEmptyGraph() { if ( perfComposite.isDisposed() ) { return; } emptyGraph = true; Label label = new Label( perfComposite, SWT.CENTER ); label.setText( BaseMessages.getString( PKG, "TransLog.Dialog.PerformanceMonitoringNotEnabled.Message" ) ); label.setBackground( perfComposite.getBackground() ); label.setFont( GUIResource.getInstance().getFontMedium() ); FormData fdLabel = new FormData(); fdLabel.left = new FormAttachment( 5, 0 ); fdLabel.right = new FormAttachment( 95, 0 ); fdLabel.top = new FormAttachment( 5, 0 ); label.setLayoutData( fdLabel ); Button button = new Button( perfComposite, SWT.CENTER ); button.setText( BaseMessages.getString( PKG, "TransLog.Dialog.PerformanceMonitoring.Button" ) ); button.setBackground( perfComposite.getBackground() ); button.setFont( GUIResource.getInstance().getFontMedium() ); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { TransGraph.editProperties( spoon.getActiveTransformation(), spoon, spoon.rep, true, TransDialog.Tabs.MONITOR_TAB ); } } ); FormData fdButton = new FormData(); fdButton.left = new FormAttachment( 40, 0 ); fdButton.right = new FormAttachment( 60, 0 ); fdButton.top = new FormAttachment( label, 5 ); button.setLayoutData( fdButton ); perfComposite.layout( true, true ); }
Example 14
Source File: MultipleSelectionCombo.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void init() { GridLayout layout = new GridLayout( 2, false ); layout.marginBottom = 0; layout.marginTop = 0; layout.marginLeft = 0; layout.marginRight = 0; layout.marginWidth = 0; layout.marginHeight = 0; setLayout( layout ); displayText = new Text( this, SWT.SINGLE ); displayText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); arrow = new Button( this, SWT.ARROW | SWT.DOWN ); arrow.setBackground( Display.getCurrent().getSystemColor( SWT.COLOR_BLUE ) ); arrow.setSize( 25, 25 ); arrow.setLocation( displayText.getLocation() ); arrow.addMouseListener( new MouseAdapter() { @Override public void mouseDown( MouseEvent event ) { super.mouseDown( event ); if ( floatShell == null || floatShell.isDisposed() ) { initFloatShell(); } else { closeShellAndUpdate(); } } } ); }
Example 15
Source File: HopGuiPipelinePerfDelegate.java From hop with Apache License 2.0 | 5 votes |
/** * Tell the user that the pipeline is not running or that there is no monitoring configured. */ private void showEmptyGraph() { if ( perfComposite.isDisposed() ) { return; } emptyGraph = true; Label label = new Label( perfComposite, SWT.CENTER ); label.setText( BaseMessages.getString( PKG, "PipelineLog.Dialog.PerformanceMonitoringNotEnabled.Message" ) ); label.setBackground( perfComposite.getBackground() ); label.setFont( GuiResource.getInstance().getFontMedium() ); FormData fdLabel = new FormData(); fdLabel.left = new FormAttachment( 5, 0 ); fdLabel.right = new FormAttachment( 95, 0 ); fdLabel.top = new FormAttachment( 5, 0 ); label.setLayoutData( fdLabel ); Button button = new Button( perfComposite, SWT.CENTER ); button.setText( BaseMessages.getString( PKG, "PipelineLog.Dialog.PerformanceMonitoring.Button" ) ); button.setBackground( perfComposite.getBackground() ); button.setFont( GuiResource.getInstance().getFontMedium() ); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { pipelineGraph.editProperties( pipelineGraph.getPipelineMeta(), hopGui, true, PipelineDialog.Tabs.MONITOR_TAB ); } } ); FormData fdButton = new FormData(); fdButton.left = new FormAttachment( 40, 0 ); fdButton.right = new FormAttachment( 60, 0 ); fdButton.top = new FormAttachment( label, 5 ); button.setLayoutData( fdButton ); perfComposite.layout( true, true ); }
Example 16
Source File: CheckBoxToolTip.java From pentaho-kettle with Apache License 2.0 | 4 votes |
protected Composite createToolTipContentArea( Event event, Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); FormLayout compLayout = new FormLayout(); compLayout.marginHeight = 5; compLayout.marginWidth = 5; composite.setLayout( compLayout ); composite.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) ); Label imageLabel = new Label( composite, SWT.NONE ); imageLabel.setImage( image ); imageLabel.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) ); FormData fdImageLabel = new FormData(); fdImageLabel.left = new FormAttachment( 0, 0 ); fdImageLabel.top = new FormAttachment( 0, 0 ); imageLabel.setLayoutData( fdImageLabel ); Label titleLabel = new Label( composite, SWT.LEFT ); titleLabel.setText( title ); titleLabel.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) ); titleLabel.setFont( GUIResource.getInstance().getFontBold() ); FormData fdTitleLabel = new FormData(); fdTitleLabel.left = new FormAttachment( imageLabel, 20 ); fdTitleLabel.top = new FormAttachment( 0, 0 ); titleLabel.setLayoutData( fdTitleLabel ); Label line = new Label( composite, SWT.SEPARATOR | SWT.HORIZONTAL ); line.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) ); FormData fdLine = new FormData(); fdLine.left = new FormAttachment( imageLabel, 5 ); fdLine.right = new FormAttachment( 100, -5 ); fdLine.top = new FormAttachment( titleLabel, 5 ); line.setLayoutData( fdLine ); // Text messageLabel = new Text(composite, SWT.LEFT | ( showingScrollBars ? SWT.H_SCROLL | SWT.V_SCROLL : SWT.NONE ) // ); /* * Text messageLabel = new Text(composite, SWT.SINGLE | SWT.LEFT); messageLabel.setText(message); * messageLabel.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); FormData fdMessageLabel = new * FormData(); fdMessageLabel.left = new FormAttachment(imageLabel, 20); fdMessageLabel.top = new * FormAttachment(line, 5); if (showingScrollBars) { fdMessageLabel.right = new FormAttachment(imageLabel, 500); * fdMessageLabel.bottom= new FormAttachment(line, 400); } messageLabel.setLayoutData(fdMessageLabel); */ Label messageLabel = new Label( composite, SWT.LEFT ); messageLabel.setText( message ); messageLabel.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) ); FormData fdMessageLabel = new FormData(); fdMessageLabel.left = new FormAttachment( imageLabel, 20 ); fdMessageLabel.top = new FormAttachment( line, 5 ); messageLabel.setLayoutData( fdMessageLabel ); final Button disable = new Button( composite, SWT.CHECK ); disable.setText( checkBoxMessage ); disable.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) ); disable.setSelection( false ); FormData fdDisable = new FormData(); fdDisable.left = new FormAttachment( 0, 0 ); fdDisable.top = new FormAttachment( messageLabel, 20 ); fdDisable.bottom = new FormAttachment( 100, 0 ); disable.setLayoutData( fdDisable ); disable.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { for ( CheckBoxToolTipListener listener : listeners ) { listener.checkBoxSelected( false ); } hide(); } } ); disable.addPaintListener( new PaintListener() { public void paintControl( PaintEvent arg0 ) { checkBoxBounds = disable.getBounds(); } } ); composite.layout(); checkBoxBounds = disable.getBounds(); return composite; }
Example 17
Source File: MultiChoice.java From nebula with Eclipse Public License 2.0 | 4 votes |
/** * Create the popup that contains all checkboxes */ private void createPopup() { this.popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP); this.popup.setLayout(new FillLayout()); final int[] popupEvents = { SWT.Close, SWT.Deactivate, SWT.Dispose }; for (final int popupEvent : popupEvents) { this.popup.addListener(popupEvent, this.listener); } if (this.elements == null) { return; } this.scrolledComposite = new ScrolledComposite(this.popup, SWT.BORDER | SWT.V_SCROLL); final Composite content = new Composite(this.scrolledComposite, SWT.NONE); content.setLayout(new GridLayout(this.numberOfColumns, true)); this.checkboxes = new ArrayList<>(this.elements.size()); for (final T o : this.elements) { final Button checkBoxButton = new Button(content, SWT.CHECK); if (this.font != null) { checkBoxButton.setFont(this.font); } if (this.foreground != null) { checkBoxButton.setForeground(this.foreground); } if (this.background != null) { checkBoxButton.setBackground(this.background); } checkBoxButton.setEnabled(text.getEditable()); checkBoxButton.setData(o); checkBoxButton.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false)); checkBoxButton.setText(this.labelProvider.getText(o)); checkBoxButton.addListener(SWT.Selection, e -> { if (checkBoxButton.getSelection()) { MultiChoice.this.selection.add(o); } else { MultiChoice.this.selection.remove(o); } MultiChoice.this.lastModified = o; setLabel(); }); if (this.selectionListener != null) { checkBoxButton.addSelectionListener(this.selectionListener); } checkBoxButton.setSelection(this.selection.contains(o)); this.checkboxes.add(checkBoxButton); } this.scrolledComposite.setContent(content); this.scrolledComposite.setExpandHorizontal(false); this.scrolledComposite.setExpandVertical(true); content.pack(); this.preferredHeightOfPopup = content.getSize().y; }
Example 18
Source File: ConfigOptionController.java From tesb-studio-se with Apache License 2.0 | 4 votes |
@Override public Control createControl(Composite subComposite, IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) { Button theBtn = getWidgetFactory().createButton(subComposite, "", SWT.PUSH); //$NON-NLS-1$ theBtn.setBackground(subComposite.getBackground()); if (param.getDisplayName().equals("")) { //$NON-NLS-1$ theBtn.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON))); } else { theBtn.setText(param.getDisplayName()); } FormData data = new FormData(); if (isInWizard()) { if (lastControl != null) { data.right = new FormAttachment(lastControl, 0); } else { data.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE); } } else { if (lastControl != null) { data.left = new FormAttachment(lastControl, 0); } else { data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0); } } data.top = new FormAttachment(0, top); theBtn.setLayoutData(data); theBtn.setEnabled(!param.isReadOnly()); theBtn.setData(param); hashCurControls.put(param.getName(), theBtn); theBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Command cmd = createCommand((Button) e.getSource()); executeCommand(cmd); } }); Point initialSize = theBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT); dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE); if (nexusServerBean == null) { theBtn.setVisible(false); } Display.getDefault().asyncExec(new Runnable() { @Override public void run() { refresh(param, true); } }); return theBtn; }
Example 19
Source File: CheckboxCellContentProvider.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * If the enabled/disabled checked/unchecked checkbox <code>Image</code>s * have not already been created and added to the JFace * <code>ImageRegistry</code>, this method generates and registers them. * This produces platform-specific images at run-time. * * @param display * The <code>Display</code> shared with the underlying * <code>ColumnViewer</code>. * @param background * The background of the <code>ColumnViewer</code>'s cells. */ private static void registerImages(final Display display, Color background) { if (display != null && IMAGES_REGISTERED.compareAndSet(false, true)) { // Get the ImageRegistry for JFace images. We will load up images // for each combination of checkbox enabled/disabled and // checked/unchecked. ImageRegistry jfaceImages = JFaceResources.getImageRegistry(); // Create a temporary shell and checkbox Button to generate // platform-specific images of checkboxes. Shell shell = new Shell(display, SWT.NO_TRIM); Button checkbox = new Button(shell, SWT.CHECK); // Set the widget's background to the viewer's cell background. checkbox.setBackground(background); // Reduce the size of the shell to a square (checkboxes are supposed // to be square!!!). Point size = checkbox.computeSize(SWT.DEFAULT, SWT.DEFAULT); // int width = Math.min(size.x, size.y); checkbox.setSize(size); // checkbox.setLocation(width - size.x, width - size.y); // shell.setSize(width, width); shell.setSize(size); // Open the shell to enable widget drawing. shell.open(); // Create the enabled/unchecked image. jfaceImages.put(ENABLED_UNCHECKED, createImage(checkbox)); // Create the enabled/checked image. checkbox.setSelection(true); jfaceImages.put(ENABLED_CHECKED, createImage(checkbox)); // Create the disabled/checked image. checkbox.setEnabled(false); jfaceImages.put(DISABLED_CHECKED, createImage(checkbox)); // Create the disabled/unchecked image. checkbox.setSelection(false); jfaceImages.put(DISABLED_UNCHECKED, createImage(checkbox)); // Release any remaining resources. // gc.dispose(); shell.close(); } return; }
Example 20
Source File: EmulatedNativeCheckBoxLabelProvider.java From Pydev with Eclipse Public License 1.0 | 4 votes |
private Image makeShot(Control control, boolean type) { /* Hopefully no platform uses exactly this color because we'll make it transparent in the image.*/ Color greenScreen = new Color(control.getDisplay(), 222, 223, 224); shell = new Shell(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.NO_TRIM | SWT.NO_BACKGROUND); // otherwise we have a default gray color shell.setBackground(greenScreen); Button button = new Button(shell, SWT.CHECK | SWT.NO_BACKGROUND); button.setBackground(greenScreen); button.setSelection(type); // otherwise an image is located in a corner button.setLocation(1, 1); Point bsize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); // otherwise an image is stretched by width bsize.x = Math.max(bsize.x - 1, bsize.y - 1); bsize.y = Math.max(bsize.x - 1, bsize.y - 1); button.setSize(bsize); GC gc = new GC(shell); Point shellSize = new Point(32, 32); shell.setSize(shellSize); shell.open(); Image image = new Image(control.getDisplay(), bsize.x, bsize.y); gc.copyArea(image, 0, 0); gc.dispose(); shell.close(); ImageData imageData = image.getImageData(); imageData.transparentPixel = imageData.palette.getPixel(greenScreen .getRGB()); Image img = new Image(control.getDisplay(), imageData); image.dispose(); return img; }