2012-07-24 72 views
0

我已經在SWT中的TabFolder下創建了兩個展開欄。然後我將Tab Foloder的佈局設置爲FillLayout(SWT.HORIZONTAL)。它在選項卡文件夾中顯示兩個展開欄。 但是,當我將標籤文件夾更改爲具有相同佈局的CTabFolder時,它不顯示我在CTabFolder下的任何展開欄。可能是什麼問題?我需要爲此設置任何參數嗎?請參閱我的下面的代碼TabFolder和CTabFolder。CTabFolder佈局控件不呈現

代碼TabFolder中:

public class Snippet223 { 

    public static void main(String[] args) { 
     Display display = new Display(); 
     Shell shell = new Shell(display); 
     shell.setLayout(new FillLayout()); 
     shell.setText("ExpandBar Example"); 
     final TabFolder folder = new TabFolder(shell, SWT.BORDER); 
     folder.setLayout(new FillLayout(SWT.HORIZONTAL)); 
     ExpandBar bar = new ExpandBar(folder, SWT.V_SCROLL); 
     ExpandBar bar1 = new ExpandBar(folder, SWT.V_SCROLL); 
     Image image = display.getSystemImage(SWT.ICON_QUESTION); 
     // First item 
     createContentsForExpandableBar(bar, image); 
     createContentsForExpandableBar(bar1, image); 
     shell.setSize(400, 350); 
     shell.open(); 
     while (!shell.isDisposed()) { 
      if (!display.readAndDispatch()) { 
       display.sleep(); 
      } 
     } 
     display.dispose(); 
    } 

    private static void createContentsForExpandableBar(ExpandBar bar, 
      Image image) { 
     Composite composite = new Composite(bar, SWT.NONE); 
     GridLayout layout = new GridLayout(); 
     layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; 
     layout.verticalSpacing = 10; 
     composite.setLayout(layout); 
     Button button = new Button(composite, SWT.PUSH); 
     button.setText("SWT.PUSH"); 
     button = new Button(composite, SWT.RADIO); 
     button.setText("SWT.RADIO"); 
     button = new Button(composite, SWT.CHECK); 
     button.setText("SWT.CHECK"); 
     button = new Button(composite, SWT.TOGGLE); 
     button.setText("SWT.TOGGLE"); 
     ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); 
     item0.setText("What is your favorite button"); 
     item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); 
     item0.setControl(composite); 
     item0.setImage(image); 
    } 

} 

代碼的CTabFolder:

public class Snippet223 { 

    public static void main(String[] args) { 
     Display display = new Display(); 
     Shell shell = new Shell(display); 
     shell.setLayout(new FillLayout()); 
     shell.setText("ExpandBar Example"); 
     final CTabFolder folder = new CTabFolder(shell, SWT.BORDER); 
     folder.setLayout(new FillLayout(SWT.HORIZONTAL)); 
     ExpandBar bar = new ExpandBar(folder, SWT.V_SCROLL); 
     ExpandBar bar1 = new ExpandBar(folder, SWT.V_SCROLL); 
     Image image = display.getSystemImage(SWT.ICON_QUESTION); 
     // First item 
     createContentsForExpandableBar(bar, image); 
     createContentsForExpandableBar(bar1, image); 
     shell.setSize(400, 350); 
     shell.open(); 
     while (!shell.isDisposed()) { 
      if (!display.readAndDispatch()) { 
       display.sleep(); 
      } 
     } 
     display.dispose(); 
    } 

    private static void createContentsForExpandableBar(ExpandBar bar, 
      Image image) { 
     Composite composite = new Composite(bar, SWT.NONE); 
     GridLayout layout = new GridLayout(); 
     layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; 
     layout.verticalSpacing = 10; 
     composite.setLayout(layout); 
     Button button = new Button(composite, SWT.PUSH); 
     button.setText("SWT.PUSH"); 
     button = new Button(composite, SWT.RADIO); 
     button.setText("SWT.RADIO"); 
     button = new Button(composite, SWT.CHECK); 
     button.setText("SWT.CHECK"); 
     button = new Button(composite, SWT.TOGGLE); 
     button.setText("SWT.TOGGLE"); 
     ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); 
     item0.setText("What is your favorite button"); 
     item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); 
     item0.setControl(composite); 
     item0.setImage(image); 
    } 

} 

回答

2

你需要創建下TabFolder中/的CTabFolder一個的TabItem/CTabItem和內容添加到那。您不應該在選項卡文件夾本身上設置佈局。從Java文檔的CTabFolder:

注意,雖然這個類是Composite, 一個子類是沒有意義在其上設置的佈局。

+0

確定。謝謝,我會做出相應的! – user414967 2012-07-24 12:21:56