swt - 在 SWT 中更改组小部件标题颜色

标签 swt eclipse-rcp

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

最佳答案

更改组的字体非常容易,请检查此代码段(使用来自 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 平台相关的错误。

关于swt - 在 SWT 中更改组小部件标题颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7117408/

相关文章:

java - CheckedTreeSelectionDialog 最初检查元素

java按钮按下3秒

java - 在哪里/如何获取 PDE 构建目标平台插件?

java - 为新的 SWTBot Eclipse 运行配置指定默认产品

java - ContentProvider 的 getChildren() 是否在 ITreeViewerListener 的 treeExpanded() 之前调用?

java - SWT是建立在Native界面之上的,但是为什么渲染并不慢

java - 当 SWT 列表处于禁用状态时,是否可以使垂直/水平滚动条可见?

java - 布局忽略了希望增长的控件?

eclipse - 如何为 Eclipse PDE 安装 GEF/Draw2d source/javadoc?

java - Eclipse插件: Implement Quick Fix proposals on hovering over errors