gpt4 book ai didi

swt - 在图像背景上放置图像按钮

转载 作者:行者123 更新时间:2023-12-04 19:49:59 24 4
gpt4 key购买 nike

我正在尝试将带有图像 (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();
}

最佳答案

摆脱按钮周围空间的唯一方法是设置背景 Color 或背景 Image

button.setBackgroundImage(image);

但是,如果按钮不在左上角(目前是这样),则背景图像将无法正确定位。所以首先你必须定位按钮,然后制作背景适当部分的图像,然后将其设置为按钮作为背景图像。

查看文章Taking a look at SWT Images - Transparency有关 Label(以及 Button)透明度的更多详细信息。

关于swt - 在图像背景上放置图像按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7255880/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com