[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: TabItem visibility

Below is the snippet I came up with based on Grant's response (not exact though as I am passing in the tabFolder on recreation of the tabItem, and not doing the setControl as he mentioned). Whats the reason that visibility is not a behavior available on org.eclipse.swt.widgets.Item just like it is on Control?

Disposing/recreating seems unnecessary to me for something like toggling visibility.

Nik

--------------------------------------------------------------
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class CompositeTester extends Composite {

	private TabFolder tabFolder;
	private static final String SHOW = "Show TabItemOne";
	private static final String HIDE = "Hide TabItemOne";
	private TabItem tabItemTwo;
	private TabItem tabItemOne;
	private boolean show = true;

	public CompositeTester(Composite parent, int style) {
		super(parent, style);
		setLayout(new FillLayout());

		tabFolder = new TabFolder(this, SWT.NONE);

		createTabitemOne();

		createTabItemTwo();

		final Composite composite = new Composite(this, SWT.NONE);
		composite.setLayout(new FillLayout());

		final Button hideButton = new Button(composite, SWT.NONE);
		hideButton.addSelectionListener(new SelectionAdapter() {

			public void widgetSelected(SelectionEvent e) {
				if(show)
				{
					tabItemOne.dispose();
					hideButton.setText(SHOW);
					show = false;
				}
				else
				{
					createTabitemOne();
					tabItemOne.setControl(tabFolder);
					hideButton.setText(HIDE);
					show = true;
				}
			}
		});
		hideButton.setText(HIDE);
		
		
		//
	}

	private void createTabItemTwo() {
		tabItemTwo = new TabItem(tabFolder, SWT.NONE);
		tabItemTwo.setText("TabItemTwo");
	}

	private void createTabitemOne() {
		tabItemOne = new TabItem(tabFolder, SWT.NONE);
		tabItemOne.setText("TabItemOne");
	}

	@Override
	public void dispose() {
		super.dispose();
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
	
	public static void main (String [] args) {
	    Display display = new Display();
	    Shell shell = new Shell (display);
	    shell.setLayout(new FillLayout());
	    CompositeTester tester = new CompositeTester(shell, SWT.CENTER);
	    shell.open ();
	    while (!shell.isDisposed ()) {
	        if (!display.readAndDispatch ()) display.sleep ();
	    }
	    display.dispose ();
	}

}

Grant Gayed wrote:
Hi Frank,

TabItems cannot be hidden, they can only be created and disposed.  So you
can "hide" it by disposing and later re-creating the tab.  You will not have
to re-create all of the tab's controls in this scenario since they're
parented on the TabFolder, you can just use
myRecreatedTabItem.setControl(theCompositeThatHoldsTheSetOfControlsThatWereO
nThePreviousInstanceOfThisTab).

Grant


"frank Buloup" <buloup@xxxxxxxxxxxxxxxx> wrote in message news:ekjhdq$3f8$1@xxxxxxxxxxxxxxxxxxxx
Hello,

Do you know how to set the visibility of a TabItem in a TabFolder ?

thanks a lot,
regards,
frank