如何将滚动条添加到TabItem



我有以下方法,它创建了一个包含两个选项卡(TabItem)的TabFolder

protected Control createContents(Composite parent) {
    Control control = super.createContents(parent);
    // 1. Create a TabFolder (dialogArea is a Control)
    TabFolder folder = new TabFolder((Composite) dialogArea, SWT.TOP);
    // 2. Create tab 1
    TabItem firstTab = new TabItem(folder, SWT.NONE);
    firstTab.setText("Tab One");
    firstTab.setControl(createMyFirstComposite(folder));
    // 3. Create tab 2
    TabItem secondTab = new TabItem(folder, SWT.NONE);
    secondTab.setText("Tab Two");
    secondTab.setControl(createMySecondComposite(folder));
    // TODO: Make the tab content scrollable
    return control;
}

由于选项卡的内容包含许多元素(在createMyFirstComposite(folder)createMySecondComposite(folder)中创建),我想在其中添加滚动条

我该怎么做?

更新:尝试按照Greg:的建议实现ScrolledComposite

protected Control createContents(Composite parent) {
    Control control = super.createContents(parent);
    TabFolder folder = new TabFolder((Composite) dialogArea, SWT.TOP);
    TabItem firstTab = new TabItem(folder, SWT.NONE);
    firstTab.setText("Tab One");
    ScrolledComposite sc = new ScrolledComposite(folder, SWT.V_SCROLL | SWT.H_SCROLL);
    sc.setExpandHorizontal(true);
    // createMyFirstComposite() returns composite with controlls
    Composite body = createMyFirstComposite(folder);
    sc.setContent(body);
    sc.setMinSize(body.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    firstTab.setControl(sc);
    // second tab...
    return control;
}

不幸的是,标签中没有任何内容。我是否忽略了什么?

使用ScrolledCompositeTabItem的控件。类似于:

TabItem firstTab = new TabItem(folder, SWT.NONE);
ScrolledComposite sc = new ScrolledComposite(folder, SWT.V_SCROLL | SWT.H_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
Composite body = // TODO create all body controls of the tab
sc.setContent(body);
sc.setMinSize(body.computeSize(SWT.DEFAULT, SWT.DEFAULT));
firstTab.setControl(sc);

最新更新