如何消除 Windows 7 中丑陋的 SWT 按钮边缘?
我维护一个必须在 Windows XP 以及 Windows 7 中运行的 SWT/JFace 应用程序。 该应用程序有一个 TabFolder
,其中包含一个 Composite
,而后者又包含小部件。没有什么异常,一切正常,除了...
按钮
虽然它们在 Windows XP 中看起来不错,但在 Windows 7 中却有一个丑陋的灰色边框。
我可以手动设置按钮的背景,但我无法找出一个 找出父母实际背景颜色的方法。即使背景实际上是白色,getBackground()
也始终返回 240, 240, 240。
我发现在Windows XP中,TabFolder的背景是主题颜色3D对象,而在Windows 7中则没有这种对应关系。我试图设置每一个 主题颜色为亮红色,但 TabFolder 背景颜色没有留下深刻的印象。
因此,SWT 按钮本身没有正确设置其背景颜色,而且我看不出有什么方法可以通过编程找出正确的颜色。我应该怎么办?
无论如何,这里是重现该问题的完整最小示例的代码:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
public class TabTest {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
TabFolder tabFolder = new TabFolder (shell, SWT.NONE);
TabItem item = new TabItem (tabFolder, SWT.NULL);
item.setText ("Tab Item");
Composite comp = new Composite(tabFolder, SWT.NONE);
comp.setLayout(new RowLayout());
item.setControl(comp);
Button button = new Button(comp, SWT.PUSH);
button.setText("Button ");
tabFolder.setSize (160, 100);
//Event Loop
shell.pack ();
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
I maintain a SWT/JFace application that has to run in Windows XP as well as Windows 7.
The application has a TabFolder
that contains a Composite
, that in turn contains the widgets. Nothing unusual and everything works well except for...
The Buttons
While they look OK in Windows XP they have an ugly grey border in Windows 7.
I could set the background of the button manually but I failed to figure out a
way to find out the parents actual background color. getBackground()
returns always 240, 240, 240 even if the background is actually white.
I found out that in Windows XP the background of a TabFolder is the theme color 3D Objects while in Windows 7 there is not such correspondence. I tried to set every single
theme color to bright red but the TabFolder background color was unimpressed.
So the SWT buttons don't set their background color correctly themselves and I see no way to find out the correct color programatically. What should I do?
Anyway, here is the code for a complete minimal example to reproduce the problem:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
public class TabTest {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
TabFolder tabFolder = new TabFolder (shell, SWT.NONE);
TabItem item = new TabItem (tabFolder, SWT.NULL);
item.setText ("Tab Item");
Composite comp = new Composite(tabFolder, SWT.NONE);
comp.setLayout(new RowLayout());
item.setControl(comp);
Button button = new Button(comp, SWT.PUSH);
button.setText("Button ");
tabFolder.setSize (160, 100);
//Event Loop
shell.pack ();
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它看起来更像是一个平台问题而不是 SWT 问题。虽然不相关,但
存在一个平台特定错误
,它可能与您当前的问题相关,也可能无关。TabFolder
的 setBackground()一种解决方法是使用
CTabFolder
。请参阅以下代码片段和输出:在 Windows 7 上输出,使用 JDK 1.6_b30、Eclipse 3.7
代码:
It seems more like a platform issue than a SWT problem. Although not related but there was a platform specific bug for
setBackground()
ofTabFolder
, it may or may not be related to your current problem.One workaround is to use
CTabFolder
. See the below snippet and output:Output on Windows 7, using JDK 1.6_b30, Eclipse 3.7
Code:
在包含按钮的组合中,将背景模式设置为 SWT.INHERIT_FORCE
In your composite that holds the button set the background mode to SWT.INHERIT_FORCE