【发布时间】:2011-08-19 05:42:49
【问题描述】:
我有一个 SWT 窗口,其中有一个组小部件,我在其中放置了几个其他小部件,我设置了组的标题及其工作正常。组标题颜色始终为蓝色(在我的情况下我不确定)并且不会与组内的其他孩子同步。所以我想知道是否有办法更改组 标题文本颜色和字体是否有办法?
【问题讨论】:
标签: swt eclipse-rcp
我有一个 SWT 窗口,其中有一个组小部件,我在其中放置了几个其他小部件,我设置了组的标题及其工作正常。组标题颜色始终为蓝色(在我的情况下我不确定)并且不会与组内的其他孩子同步。所以我想知道是否有办法更改组 标题文本颜色和字体是否有办法?
【问题讨论】:
标签: swt eclipse-rcp
更改组的字体很容易,检查这个sn-p(使用sn-p from java2s.com)
//Send questions, comments, bug reports, etc. to the authors:
//Rob Warner (rwarner@interspatial.com)
//Robert Harris (rbrt_harris@yahoo.com)
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
/**
* This class demonstrates groups
*/
public class GroupExample {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
// Create the first group
Group group1 = new Group(shell, SWT.SHADOW_IN);
group1.setText("Who's your favorite?");
group1.setLayout(new RowLayout(SWT.VERTICAL));
group1.setFont(new Font(display, "Consolas", 10, SWT.BOLD));
new Button(group1, SWT.RADIO).setText("John");
new Button(group1, SWT.RADIO).setText("Paul");
new Button(group1, SWT.RADIO).setText("George");
new Button(group1, SWT.RADIO).setText("Ringo");
// Create the second group
Group group2 = new Group(shell, SWT.NO_RADIO_GROUP);
group2.setText("Who's your favorite?");
group2.setLayout(new RowLayout(SWT.VERTICAL));
group2.setForeground(new Color(display, new RGB(255, 0, 0)));
new Button(group2, SWT.RADIO).setText("Barry");
new Button(group2, SWT.RADIO).setText("Robin");
new Button(group2, SWT.RADIO).setText("Maurice");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
它在 W7 上提供了这种行为
但正如您所见,setForeground(Color c) 更改颜色并没有改变任何事情,当我搜索其他信息时,我发现了有关 SWT bugzilla The color of the title of the group control cannot be changed 的错误报告。这是 Windows 平台相关的错误。
【讨论】:
但是您可以尝试一个没有文本的组 + 一个标签小部件,如果您只是想要一个更好的 GUI,这可能是一个解决方案。
【讨论】: