CTabFolder


Selecting the default tab in CTabFolder

By default none of the CTabItems are selected and, therefore, none of them will be shown when the folder becomes visible.

To avoid the blank folder, select the tab that should display by default using the setSelection() method as shown in the last line in the following block:

		Composite container = new Composite(parent, SWT.NONE);
		container.setLayout(new GridLayout());

		// Creates the folder
		tabFolder = new CTabFolder(container, SWT.BOTTOM);
		tabFolder.setBorderVisible(true);
		tabFolder.setBackgroundMode(SWT.INHERIT_DEFAULT);
		tabFolder.setSimple(false);  // rounded tabs
		tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		//Creates the first tab
		headerTabItem = new CTabItem(tabFolder, SWT.NONE);
		headerTabItem.setText("Header");
		//Adds a composite to the tab
		offerHeaderComposite = new OfferHeaderComposite(tabFolder, SWT.NONE);
		headerTabItem.setControl(offerHeaderComposite);

		//Creates the second tab
		detailTabItem = new CTabItem(tabFolder, SWT.NONE);
		detailTabItem.setText("Detail");

		//Selects the first tab ... zero-based index
		tabFolder.setSelection(0);

You must be logged in to post a comment.