2014-11-24 150 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 
    } 
});