SWT按钮 - 删除按钮背景

时间:2014-11-24 16:22:03

标签: java eclipse eclipse-plugin

我有一个看起来像这样的按钮:

我想删除按钮背景..也就是说,图像将是按钮。 这是我的代码:

Button button = new Button(shell, SWT.NONE);
button.setToolTipText("Email Settings...");
button.setImage(SWTResourceManager.getImage(Settings.class, "settings1616.png"));
button.setBounds(494, 26, 28, 25);

我试过..

button.setBackground(null);
button.setBackgroundImage(null);

但它没有删除任何东西。 谢谢!

3 个答案:

答案 0 :(得分:4)

请尝试使用SWT Image HyperLink,它没有按钮背景,它可以解决您的目的。

添加org.eclipse.ui.forms作为依赖项。

ImageHyperlink hyperlink = new ImageHyperlink(parentComposite, SWT.NONE); hyperlink.setImage("image location");

答案 1 :(得分:0)

使用工具栏和工具栏。这里http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet18.java是一个有用的片段。 并使用

toolitem.setImage(Your_image);

这也适用于mac!

答案 2 :(得分:0)

在盒子外面思考。

Label button = new Label(parent, SWT.BORDER);
button.setToolTipText("Email Settings...");
button.setImage(SWTResourceManager.getImage(Settings.class, "settings1616.png"));
button.setBounds(494, 26, 28, 25);
button.setCursor(Display.getDefault().getCursor(SWT.CURSOR_HAND)); 
button.addMouseListener(new MouseAdapter()
{
    @Override public void mouseClicked(MouseEvent e)
    {
        // Do your thing
    }
});