2012-07-24 71 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