我想把图像(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