2011-08-19 143 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。