- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我是 java SWT 的新手,在放置标签时,我似乎无法使标签背景透明。我正在使用 eclipse luna SWT desine 形式。这是我的窗口的样子:
如你所见,所有的标签背景都是白色的。我应该怎么做才能使标签背景默认与窗口背景(灰色)相同(意思是 - 不是通过在运行时更改每个标签背景,这对我有用)。
它可能很简单,但我只是无法在谷歌上找到如何去做。这是我的代码:
import java.awt.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.swt.widgets.Label;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Canvas;
public class WinApp2 {
private DataBindingContext m_bindingContext;
protected Shell shell;
private Text destenation_ip;
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
private Label lblDestenationPortIp;
private Label lblNewLabel;
private Text ammount_of_packets;
private Label lblNewLabel_1;
private Text sorce_ip;
private Text destenation_port;
private Text sorce_port;
private Label lblNewLabel_2;
private Label label;
private Label label_1;
private Label ammount_of_packets_info;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
Display display = Display.getDefault();
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
try {
WinApp2 window = new WinApp2();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
shell.setSize(450, 306);
shell.setText("LAN Destroyer");
shell.setLayout(new FormLayout());
destenation_ip = new Text(shell, SWT.BORDER);
FormData fd_destenation_ip = new FormData();
destenation_ip.setLayoutData(fd_destenation_ip);
lblDestenationPortIp = new Label(shell, SWT.NONE);
lblDestenationPortIp.setAlignment(SWT.RIGHT);
FormData fd_lblDestenationPortIp = new FormData();
fd_lblDestenationPortIp.left = new FormAttachment(0, 351);
fd_lblDestenationPortIp.right = new FormAttachment(100, -10);
fd_lblDestenationPortIp.top = new FormAttachment(0, 35);
lblDestenationPortIp.setLayoutData(fd_lblDestenationPortIp);
lblDestenationPortIp.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
formToolkit.adapt(lblDestenationPortIp, true, true);
lblDestenationPortIp.setText(":\u05E9\u05DC \u05D9\u05E2\u05D3 IP");
lblNewLabel = new Label(shell, SWT.NONE);
lblNewLabel.setAlignment(SWT.RIGHT);
FormData fd_lblNewLabel = new FormData();
fd_lblNewLabel.right = new FormAttachment(100, -10);
lblNewLabel.setLayoutData(fd_lblNewLabel);
formToolkit.adapt(lblNewLabel, true, true);
lblNewLabel.setText(":\u05DB\u05DE\u05D5\u05EA");
ammount_of_packets = new Text(shell, SWT.BORDER);
fd_destenation_ip.left = new FormAttachment(ammount_of_packets, 0, SWT.LEFT);
fd_destenation_ip.right = new FormAttachment(ammount_of_packets, -1, SWT.RIGHT);
FormData fd_ammount_of_packets = new FormData();
fd_ammount_of_packets.right = new FormAttachment(lblNewLabel, -68);
fd_ammount_of_packets.top = new FormAttachment(lblNewLabel, -3, SWT.TOP);
ammount_of_packets.setLayoutData(fd_ammount_of_packets);
formToolkit.adapt(ammount_of_packets, true, true);
Button nonstop_send = new Button(shell, SWT.CHECK);
fd_ammount_of_packets.left = new FormAttachment(0, 186);
nonstop_send.setAlignment(SWT.RIGHT);
nonstop_send.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if(nonstop_send.getSelection()){
ammount_of_packets_info.setText("שולח ללא הפסקה");
ammount_of_packets_info.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN));
ammount_of_packets.setEnabled(false);
}
else {
ammount_of_packets_info.setText("");
ammount_of_packets.setEnabled(true);
}
}
});
FormData fd_nonstop_send = new FormData();
fd_nonstop_send.top = new FormAttachment(lblNewLabel, 0, SWT.TOP);
fd_nonstop_send.right = new FormAttachment(ammount_of_packets, -9);
nonstop_send.setLayoutData(fd_nonstop_send);
formToolkit.adapt(nonstop_send, true, true);
nonstop_send.setText("\u05E9\u05DC\u05D7 \u05DC\u05DC\u05D0 \u05D4\u05E4\u05E1\u05E7\u05D4");
lblNewLabel_1 = new Label(shell, SWT.NONE);
fd_lblNewLabel.top = new FormAttachment(lblNewLabel_1, 6);
lblNewLabel_1.setAlignment(SWT.RIGHT);
FormData fd_lblNewLabel_1 = new FormData();
fd_lblNewLabel_1.right = new FormAttachment(100, -10);
fd_lblNewLabel_1.top = new FormAttachment(lblDestenationPortIp, 6);
lblNewLabel_1.setLayoutData(fd_lblNewLabel_1);
formToolkit.adapt(lblNewLabel_1, true, true);
lblNewLabel_1.setText(":\u05E9\u05DC \u05DE\u05E7\u05D5\u05E8 IP");
sorce_ip = new Text(shell, SWT.BORDER);
fd_destenation_ip.bottom = new FormAttachment(sorce_ip);
fd_lblNewLabel_1.left = new FormAttachment(sorce_ip, 29);
FormData fd_sorce_ip = new FormData();
fd_sorce_ip.top = new FormAttachment(0, 58);
fd_sorce_ip.left = new FormAttachment(0, 186);
fd_sorce_ip.right = new FormAttachment(100, -114);
sorce_ip.setLayoutData(fd_sorce_ip);
formToolkit.adapt(sorce_ip, true, true);
destenation_port = new Text(shell, SWT.BORDER);
fd_nonstop_send.left = new FormAttachment(destenation_port, 0, SWT.LEFT);
FormData fd_destenation_port = new FormData();
fd_destenation_port.top = new FormAttachment(0, 32);
fd_destenation_port.left = new FormAttachment(0, 40);
destenation_port.setLayoutData(fd_destenation_port);
formToolkit.adapt(destenation_port, true, true);
sorce_port = new Text(shell, SWT.BORDER);
sorce_port.setForeground(SWTResourceManager.getColor(SWT.COLOR_CYAN));
sorce_port.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
FormData fd_sorce_port = new FormData();
fd_sorce_port.top = new FormAttachment(lblNewLabel_1, -3, SWT.TOP);
fd_sorce_port.left = new FormAttachment(destenation_port, 0, SWT.LEFT);
sorce_port.setLayoutData(fd_sorce_port);
formToolkit.adapt(sorce_port, true, true);
lblNewLabel_2 = new Label(shell, SWT.NONE);
FormData fd_lblNewLabel_2 = new FormData();
fd_lblNewLabel_2.top = new FormAttachment(0, 35);
fd_lblNewLabel_2.left = new FormAttachment(destenation_port, 6);
lblNewLabel_2.setLayoutData(fd_lblNewLabel_2);
formToolkit.adapt(lblNewLabel_2, true, true);
lblNewLabel_2.setText(":\u05E4\u05D5\u05E8\u05D8");
label = new Label(shell, SWT.NONE);
label.setText(":\u05E4\u05D5\u05E8\u05D8");
FormData fd_label = new FormData();
fd_label.bottom = new FormAttachment(nonstop_send, -6);
fd_label.left = new FormAttachment(sorce_port, 6);
label.setLayoutData(fd_label);
formToolkit.adapt(label, true, true);
label_1 = new Label(shell, SWT.WRAP | SWT.SHADOW_IN);
FormData fd_label_1 = new FormData();
fd_label_1.top = new FormAttachment(ammount_of_packets, 20);
fd_label_1.left = new FormAttachment(0, 187);
label_1.setLayoutData(fd_label_1);
formToolkit.adapt(label_1, true, true);
label_1.setText(":\u05E1\u05D9\u05DB\u05D5\u05DD");
ammount_of_packets_info = new Label(shell, SWT.NONE);
ammount_of_packets_info.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_MAGENTA));
FormData fd_ammount_of_packets_info = new FormData();
fd_ammount_of_packets_info.left = new FormAttachment(100, -158);
fd_ammount_of_packets_info.top = new FormAttachment(ammount_of_packets, 44);
fd_ammount_of_packets_info.right = new FormAttachment(100, -36);
ammount_of_packets_info.setLayoutData(fd_ammount_of_packets_info);
formToolkit.adapt(ammount_of_packets_info, true, true);
m_bindingContext = initDataBindings();
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
return bindingContext;
}
}
谢谢!
最佳答案
您的问题是由 FormToolkit#adapt(Control, boolean, boolean)
引起的。在内部,此方法将背景颜色设置为工具包的背景颜色。
你可以通过调用来阻止:
formToolkit.setBackground(null);
关于java - 如何在 SWT 中使标签背景透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25188687/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!