2011-08-19 137 views
4

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

回答

5

这是很容易改变组的字体,(从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 The color of the title of the group control cannot be changed的bug报告。这是Windows平台相关的错误。

1

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