SWT: scrollable area inside the tab

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

On one of my CTabItems, the content is too large to fit on the screen so I can scroll. Content is a collection of groups, each of which contains different widgets.

So 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 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);

, , , tabArea , , . , , , , . tabArea.

- , , ?

+3
1

ScrolledComposite. ( JavaDoc snippets)

, :

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);
+4

Source: https://habr.com/ru/post/1737909/


All Articles