Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » CTabFolder content display issue in combination with ScrolledComposite
CTabFolder content display issue in combination with ScrolledComposite [message #1724013] Fri, 19 February 2016 19:41 Go to next message
Artem Portnoy is currently offline Artem PortnoyFriend
Messages: 2
Registered: February 2016
Junior Member
Hi,

I have a CTabFolder with 3 CTabItem each one of which contains a ScrolledComposite. The issue is that the content of the second and third tabs is invisible until the window is either resized or after the user repeatedly clicks through the tabs. Please help!

public class TestCTabFolder {
	
	private CTabFolder tabFolder;

	public void run() {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Show CTabFolder");
		createContents(shell);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
	
	private void createContents(Shell shell) {
	    shell.setLayout(new GridLayout(1, true));

	    // Create the tabs
	    tabFolder = new CTabFolder(shell, SWT.TOP);
	    tabFolder.setBorderVisible(true);
	    tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
		tabFolder.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				tabFolder.getSelection().notifyListeners(SWT.SELECTED, new Event());
			}
		});

		CTabItem firstTab = addTab("tab1");
		addTab("tab2");
		addTab("tab3");
		
		tabFolder.setSelection(firstTab);
	}

	private CTabItem addTab(String title) {
		CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
		tabItem.setText(title);
		
		final ScrolledComposite scrolledComp = new ScrolledComposite(tabFolder, SWT.V_SCROLL);
		final Composite comp = new Composite(scrolledComp, SWT.NONE);
		scrolledComp.setContent(comp);
		comp.setLayout(new GridLayout(1, true));
		comp.setLayoutData(new GridData(GridData.FILL_BOTH));
		
		for (int i = 0; i < 30; i++) {
			Label label = new Label(comp, SWT.NONE);
			label.setText(title + ": label" + i);
		}
		
		scrolledComp.setExpandVertical(true);
		scrolledComp.setExpandHorizontal(true);
		scrolledComp.setMinSize(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		tabItem.setControl(scrolledComp);
		tabItem.addListener(SWT.SELECTED, new Listener() {
			@Override
			public void handleEvent(Event event) {
				scrolledComp.layout(true);
			}
		});
		return tabItem;
	}
	
	public static void main(String[] args) {
		new TestCTabFolder().run();
	}
}


Thanks,
Artem
Re: CTabFolder content display issue in combination with ScrolledComposite [message #1724416 is a reply to message #1724013] Tue, 23 February 2016 19:17 Go to previous message
Artem Portnoy is currently offline Artem PortnoyFriend
Messages: 2
Registered: February 2016
Junior Member
The way to fix this was by replacing
scrolledComp.layout(true);
with
tabFolder.layout(true);
Previous Topic:use dynamic model to programing SWT
Next Topic:No more swt*.jar files?
Goto Forum:
  


Current Time: Tue Dec 12 10:42:19 GMT 2017

Powered by FUDForum. Page generated in 0.01544 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software