The SWT button image is not taking the width and height equal to the button and is leaving some margin

27 Views Asked by At

I have added a button in SWT and then added image using setImage(). There is some margin around the image. I want the image to cover the whole background of the button.

Screenshot for your reference

Section sctnScript = toolkit.createSection(this, Section.TITLE_BAR);
sctnScript.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
toolkit.paintBordersFor(sctnScript);
sctnScript.setText("Script");

Composite titleBar = toolkit.createComposite(sctnScript);
titleBar.setBackground(new Color(Display.getCurrent(), 240, 243, 247));

GridLayout titleBarLayout = new GridLayout(2, false);
titleBarLayout.marginWidth = 0;
titleBarLayout.marginHeight = 0;
titleBar.setLayout(titleBarLayout);

sctnScript.setExpanded(true);
toolBar = new ToolBar(titleBar, SWT.FLAT | SWT.RIGHT);
toolkit.paintBordersFor(toolBar);

Button button = toolkit.createButton(titleBar, "", SWT.PUSH);
GridData buttonData = new GridData(SWT.END, SWT.CENTER, false, false);
button.setBackground(new Color(Display.getCurrent(), 240, 243, 247));
button.setImage(buttonImage);
button.setSize(buttonImage.getBounds().width, buttonImage.getBounds().height);
0

There are 0 best solutions below