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

发布于 2024-11-30 15:01:50 字数 144 浏览 0 评论 0原文

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

I have an SWT window wherein there is Group widget in which i placed couple of other widgets,i set the title of group & its working fine. The group title color is blue always(in my case i am not sure) and that doesn't sync up with other children inside group.So i wonder if there is a way to change the group title text color and font if there is a way ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉溺在你眼里的海 2024-12-07 15:01:50

更改组的字体非常容易,请检查此片段(使用的片段来自 java2s.com

//Send questions, comments, bug reports, etc. to the authors:

//Rob Warner ([email protected])
//Robert Harris ([email protected])

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 上的错误报告 组控件标题的颜色无法更改。这是 Windows 平台相关的错误。

It's quite easy to change font of group, check this snippet (used snippet from java2s.com)

//Send questions, comments, bug reports, etc. to the authors:

//Rob Warner ([email protected])
//Robert Harris ([email protected])

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();
  }
}

It provides this behavior on W7

font change on group in W7

But as you can see, change of color by setForeground(Color c) doesn't change a thing, when I search for additional info I found bug report on SWT bugzilla The color of the title of the group control cannot be changed. It's windows platform dependent bug.

雨后彩虹 2024-12-07 15:01:50

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

But you can try a Group without text + a Label widget, this maybe a solution if you just want a better GUI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文