在SWT中更改组窗口小部件标题颜色

时间:2011-08-19 05:42:50

标签: swt eclipse-rcp

我有一个SWT窗口,其中有Group小部件,其中我放置了几个其他小部件,我设置了group&的标题。它的工作正常。组标题颜色总是蓝色(在我的情况下我不确定),并且不与组内的其他子项同步。所以我想知道是否有办法更改组标题文本颜色和字体,如果有办法吗?

2 个答案:

答案 0 :(得分:5)

更改组的字体非常容易,请检查此代码段(来自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上提供了这种行为

font change on group in W7

但正如您所看到的,setForeground(Color c)更改颜色并没有改变任何事情,当我搜索其他信息时,我发现了有关SWT bugzilla The color of the title of the group control cannot be changed的错误报告。这是Windows平台相关的错误。

答案 1 :(得分:1)

但是你可以尝试没有文本+ Label小部件的组,如果你只是想要一个更好的GUI,这可能是一个解决方案。

相关问题