我想把圖像(GIF)放在已經設置爲圖像的背景上(shell.setBackgroundImage(image)
),我無法弄清楚如何去除按鈕周圍的透明邊框圖片。如果有人能就這個問題給我一些建議,我將不勝感激。在圖像背景上放置圖像按鈕
這裏是我的代碼:
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
public class Main_page {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Image image = new Image(display, "bg.gif");
shell.setBackgroundImage(image);
shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
shell.setFullScreen(true);
Button button = new Button(shell, SWT.PUSH);
button.setImage(new Image(display, "button.gif"));
RowLayout Layout = new RowLayout();
shell.setLayout(Layout);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
魔法師,謝謝你的答案,我肯定會考慮this article。也許我會找到自己的方式。到目前爲止,我已經改進了一些代碼。首先,我設法擺脫了灰色的背景噪音。其次,我最終成功地創造了按鈕,正如我之前所看到的那樣。然而,另一個障礙已經出現。當我刪除圖像(按鈕)透明邊框,結果證明按鈕改變了它的模式(從按鈕到複選框)。問題是我來到了我所尋找的東西附近,現在我有些困惑。如果你有一些時間,請看一下我的代碼。
下面是代碼,如果你啓動它,你會看到的問題是什麼(希望你沒有問題,下載圖像):
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
public class Main_page {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Image image = new Image(display, "bg.gif"); // Launch on a screen 1280x1024
shell.setBackgroundImage(image);
shell.setBackgroundMode(SWT.TRANSPARENT);
shell.setFullScreen(true);
GridLayout gridLayout = new GridLayout();
gridLayout.marginTop = 200;
gridLayout.marginLeft = 20;
shell.setLayout(gridLayout);
// If you replace SWT.PUSH with SWT.COLOR_TITLE_INACTIVE_BACKGROUND
// you will see what I am looking for, despite nasty check box
Button button = new Button(shell, SWT.PUSH);
button.setImage(new Image(display, "moneyfast.gif"));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
能否請您發佈鏈接到這兩個GIF圖像? – Sorceror
這裏是他們http://file.karelia.ru/ffdgqn/ http://file.karelia.ru/d6n9dw/ – foma