2011-12-06 32 views
2

我在設計一個基於org.eclipse.swt.widgets.TabItem的gui。如何設置swt tabitem不活動?

有沒有辦法在TabFolder內顯示TabItem爲「非活動」,即使用通常的淺灰色,並且所有包含的元素都不活動?

這是我可以設計的其他系統中的東西。我認爲這也可能與SWT,但我是新來的這個環境,谷歌搜索這個主題後,我找不到任何解決方案。它有可能嗎?

回答

6

不可能將TabItem設置爲不活動(禁用),因爲那時如何點擊選中的TabItem就沒有辦法。但是很容易禁用選定的內容TabItem。剛得到Control,它綁定到TabItem實例並調用setEnable(false)

/* 
* TabFolder example snippet: create a tab folder (six pages) 
* 
* For a list of all SWT example snippets see 
* http://www.eclipse.org/swt/snippets/ 
*/ 
import org.eclipse.swt.*; 
import org.eclipse.swt.graphics.Rectangle; 
import org.eclipse.swt.widgets.*; 

public class TabItemDisable { 

public static void main (String [] args) { 
    Display display = new Display(); 
    final Shell shell = new Shell (display); 
    final TabFolder tabFolder = new TabFolder (shell, SWT.BORDER); 
    Rectangle clientArea = shell.getClientArea(); 
    tabFolder.setLocation (clientArea.x, clientArea.y); 
    for (int i=0; i<6; i++) { 
     TabItem item = new TabItem (tabFolder, SWT.NONE); 
     item.setText ("TabItem " + i); 
     Button button = new Button (tabFolder, SWT.PUSH); 
     button.setText ("Page " + i); 
     item.setControl (button); 
    } 
    tabFolder.pack(); 

    // disabling content of selected TabItems 
    tabFolder.getTabList()[0].setEnabled(false); 
    tabFolder.getTabList()[2].setEnabled(false); 
    tabFolder.getTabList()[4].setEnabled(false); 

    shell.pack(); 
    shell.open(); 
    while (!shell.isDisposed()) { 
     if (!display.readAndDispatch()) display.sleep(); 
    } 
    display.dispose(); 
} 
}