[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.platform.swt] Re: Add/remove widgets from composites
|
Items like TabItem, TableItem, MenuItem, etc. can't be made invisible, they
can only be created/disposed.
"Nik Bhattacharya" <nik_bhat@xxxxxxxxx> wrote in message
news:ekkarr$vdg$1@xxxxxxxxxxxxxxxxxxxx
> hiding/showing using visibility using setVisible(boolean) is possible if
> the child widget is a subclass of Control. However, I am unable to see
> a way to hide/show when a widget is not a Control and subclasses
> org.eclipse.swt.widgets.Item. For example, how would I hide/show a
> TabItem in a TabFolder dynamically? See snippet below:
>
> ------------------------------------------------------------------------
> 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);
>
> tabItemOne = new TabItem(tabFolder, SWT.NONE);
> tabItemOne.setText("TabItemOne");
>
> tabItemTwo = new TabItem(tabFolder, SWT.NONE);
> tabItemTwo.setText("TabItemTwo");
>
> 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)
> {
> ////////////////////////////////
> // What code goes here //
> ///////////////////////////////
> hideButton.setText(SHOW);
> show = false;
> }
> else
> {
> ////////////////////////////////
> // What code goes here //
> ///////////////////////////////
> hideButton.setText(HIDE);
> show = true;
> }
> }
> });
> hideButton.setText(HIDE);
>
>
> //
> }
>
> @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 ();
> }
>
> }
>
>
> Tom Schindl wrote:
> > Peter Maas schrieb:
> >> Is it possible to add/remove SWT widgets from composites or at least
> >> emulate this by show and hide?
> >>
> >
> > - Adding - create the new widget
> > - Removing - dispose widget
> > - Hiding - setVisible(false)
> > - Showing - setVisible(true)
> >
> > Tom