2014-11-24 149 views
0

我有一个按钮,看起来像这样: SWT按钮 - 删除按钮背景

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

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); 

但它不会删除任何东西。 谢谢!

+0

这是什么平台?在某些平台上(例如Windows),您不能像这样更改按钮背景 - http://stackoverflow.com/q/3312102/2670892 – 2014-11-24 16:27:20

+0

我正在使用Windows。这可能通过Macintosh吗? – 2014-11-24 16:28:03

+0

或只是使用可点击的JLabel与ImageIcon – 2014-11-24 16:31:22

回答

3

请尝试使用SWT图像HyperLink,这个doest有按钮背景,它解决了你的目的。

org.eclipse.ui.forms作为依赖关系。

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

+0

真棒..非常感谢:) – 2016-11-30 06:14:39

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 
    } 
});