views:

302

answers:

1

I am trying to add a scrollable area to my tabbed window. So far I have a CTabFolder in a shell. I have added 5 CTabItems to it and everything works as expected.

On one of my CTabItems the contents are too big to fit on the screen so I would like to be able to scroll. The contents is a collection of Groups each containing various widgets.

So the CTabFolder is created as follows:

CTabFolder tabs = new CTabFolder(shell, SWT.BORDER);
tabs.setSimple(false);
tabs.setUnselectedImageVisible(false);
tabs.setUnselectedCloseVisible(false);
tabs.setMinimizeVisible(false);
tabs.setMaximizeVisible(false);

FormData tabsLayoutData = new FormData();
tabsLayoutData.top = new FormAttachment(0, 5);
tabsLayoutData.left = new FormAttachment(0, 5);
tabsLayoutData.bottom = new FormAttachment(92, 0);
tabsLayoutData.right = new FormAttachment(100, -5);
tabs.setLayoutData(tabsLayoutData);

Then the CTabItem:

CTabItem tab = new CTabItem(tabs, SWT.NONE);
tab.setText("Role");

Then the contents:

Composite tabArea = new Composite(tabs, SWT.V_SCROLL); tabArea.setLayout(new FormLayout()); tab.setControl(tabArea);

So the groups contained within the tab are created with tabArea as the parent and everything appears as you would expect. The problem is though that the vertical scroll bar is always present but doesn't seem to do anything. The contents are chopped off at the bottom of the tabArea composite.

Is there anything else I need to do to get the scrolling to work properly?

+2  A: 

You need to use a ScrolledComposite. (Scroll down and find links to JavaDoc & snippets)

Here is code that should work in your situation:

ScrolledComposite scroller = new ScrolledComposite(tabs, SWT.BORDER | SWT.V_SCROLL);

Composite tabArea = new Composite(scroller, SWT.NONE); 
scroller.setContent(tabArea);

// create some controls in TabArea and assign a layout to TabArea

scroller.setExpandVertical(true);
scroller.setExpandHorizontal(true);
scroller.setMinSize(tabArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));

tab.setControl(scroller);
wsorenson