Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to remove a control from a composite?
How to remove a control from a composite? [message #458926] Tue, 26 July 2005 17:32 Go to next message
Eclipse UserFriend
Originally posted by: fmahjobi.enterasys.com

Hi,

Is there a way to dynamically remove and add back in a control from a
composite? Imagine you have a case where you want to dynamically change
the appearance based on some conditions. I know about the stacklayout that
does work quite well. Setting visibility also does not work since the
object is actually there and it is just not displayed.

Thanks.
Re: How to remove a control from a composite? [message #458937 is a reply to message #458926] Tue, 26 July 2005 19:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Farzad" <fmahjobi@enterasys.com> wrote in message
news:98c4495a6fd18c010b205b06cdf61b50$1@www.eclipse.org...
> Hi,
>
> Is there a way to dynamically remove and add back in a control from a
> composite? Imagine you have a case where you want to dynamically change
> the appearance based on some conditions. I know about the stacklayout that
> does work quite well. Setting visibility also does not work since the
> object is actually there and it is just not displayed.
>
> Thanks.
>
To remove:
dispose the control. layout the composite again.
To add back:
recreate the control. layout the composite again.
Where it shows up in the layout depends upon your layout manager.
---
Sunil
Re: How to remove a control from a composite? [message #458950 is a reply to message #458926] Wed, 27 July 2005 08:35 Go to previous messageGo to next message
Glenn Marintes is currently offline Glenn MarintesFriend
Messages: 23
Registered: July 2009
Junior Member
Hi,

> Is there a way to dynamically remove and add back in a control from a
> composite? Imagine you have a case where you want to dynamically change
> the appearance based on some conditions.
You can do this in two ways:
1. Dispose the control and create it again when needed.
This solution has its own disadvantage:
- it is difficult to create a control in the same place that it
was created before.. ie. your composite has 5 buttons, if you
dispose button 2, you can create a new button 2 later BUT
it will be added at the end of the composite.
- if for example, your composite contains a certain set of composites,
destroying the child composites will pose the same problem as stated
above + the fields in the child composite needs to be re-initialized.

2. Set the visibility of the control.
This solution needs the help of the layout manager. Basically,
once you setVisible(false) a control, the layout manager should
honor its invisibility and hence, the control is still there
but the layout manager won't show it and the layout manager
won't provide any space for it.
GridLayout in 3.1 and RowLayout can help you with this.
GridLayout 3.1 now supports invisible controls - that is, it won't
show invisible controls. If you want to hide a control, just
setVisible(false) it and then call parentComposite.layout(); If you
want to show it again, just call setVisible(true) it and then
call parentComposite.layout();

You can also use RowLayout. To effectively hide the control
call, control.setVisible(false) and then
control.setLayoutData(new RowData(0,0));
If you want to shown it again, call control.setVisible(true) and then
control.setLayoutData(new RowData(controlWidth, controlHeight));

> I know about the stacklayout
> that does work quite well. Setting visibility also does not work since
> the object is actually there and it is just not displayed.

As far as i know, stacklayout layouts components in a single stack.
that is, you can only have at most 1 control (could be a composite)
visible at any time... its pretty useless when you want to hide
just part of your composite.
Re: How to remove a control from a composite? [message #459160 is a reply to message #458950] Tue, 02 August 2005 19:06 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Actually, setVisible() alone won't do it. You'll need to also set the
exclude field in the layout data.

"Glenn Marintes" <glenn.marintes@laseritesystems.com> wrote in message
news:dc7h0s$ak0$1@news.eclipse.org...
> Hi,
>
> > Is there a way to dynamically remove and add back in a control from a
> > composite? Imagine you have a case where you want to dynamically change
> > the appearance based on some conditions.
> You can do this in two ways:
> 1. Dispose the control and create it again when needed.
> This solution has its own disadvantage:
> - it is difficult to create a control in the same place that it
> was created before.. ie. your composite has 5 buttons, if you
> dispose button 2, you can create a new button 2 later BUT
> it will be added at the end of the composite.
> - if for example, your composite contains a certain set of composites,
> destroying the child composites will pose the same problem as stated
> above + the fields in the child composite needs to be re-initialized.
>
> 2. Set the visibility of the control.
> This solution needs the help of the layout manager. Basically,
> once you setVisible(false) a control, the layout manager should
> honor its invisibility and hence, the control is still there
> but the layout manager won't show it and the layout manager
> won't provide any space for it.
> GridLayout in 3.1 and RowLayout can help you with this.
> GridLayout 3.1 now supports invisible controls - that is, it won't
> show invisible controls. If you want to hide a control, just
> setVisible(false) it and then call parentComposite.layout(); If you
> want to show it again, just call setVisible(true) it and then
> call parentComposite.layout();
>
> You can also use RowLayout. To effectively hide the control
> call, control.setVisible(false) and then
> control.setLayoutData(new RowData(0,0));
> If you want to shown it again, call control.setVisible(true) and then
> control.setLayoutData(new RowData(controlWidth, controlHeight));
>
> > I know about the stacklayout
> > that does work quite well. Setting visibility also does not work since
> > the object is actually there and it is just not displayed.
>
> As far as i know, stacklayout layouts components in a single stack.
> that is, you can only have at most 1 control (could be a composite)
> visible at any time... its pretty useless when you want to hide
> just part of your composite.
>
Re: How to remove a control from a composite? [message #459208 is a reply to message #459160] Wed, 03 August 2005 12:14 Go to previous message
Glenn Marintes is currently offline Glenn MarintesFriend
Messages: 23
Registered: July 2009
Junior Member
ah yup.. i missed that part hehehe...
Thank you for the correction..

Steve Northover wrote:
> Actually, setVisible() alone won't do it. You'll need to also set the
> exclude field in the layout data.
>
> "Glenn Marintes" <glenn.marintes@laseritesystems.com> wrote in message
> news:dc7h0s$ak0$1@news.eclipse.org...
>
>>Hi,
>>
>>
>>>Is there a way to dynamically remove and add back in a control from a
>>>composite? Imagine you have a case where you want to dynamically change
>>>the appearance based on some conditions.
>>
>>You can do this in two ways:
>>1. Dispose the control and create it again when needed.
>>This solution has its own disadvantage:
>>- it is difficult to create a control in the same place that it
>>was created before.. ie. your composite has 5 buttons, if you
>>dispose button 2, you can create a new button 2 later BUT
>>it will be added at the end of the composite.
>>- if for example, your composite contains a certain set of composites,
>>destroying the child composites will pose the same problem as stated
>>above + the fields in the child composite needs to be re-initialized.
>>
>>2. Set the visibility of the control.
>>This solution needs the help of the layout manager. Basically,
>>once you setVisible(false) a control, the layout manager should
>>honor its invisibility and hence, the control is still there
>>but the layout manager won't show it and the layout manager
>>won't provide any space for it.
>>GridLayout in 3.1 and RowLayout can help you with this.
>>GridLayout 3.1 now supports invisible controls - that is, it won't
>>show invisible controls. If you want to hide a control, just
>>setVisible(false) it and then call parentComposite.layout(); If you
>>want to show it again, just call setVisible(true) it and then
>>call parentComposite.layout();
>>
>>You can also use RowLayout. To effectively hide the control
>>call, control.setVisible(false) and then
>>control.setLayoutData(new RowData(0,0));
>>If you want to shown it again, call control.setVisible(true) and then
>>control.setLayoutData(new RowData(controlWidth, controlHeight));
>>
>>
>>>I know about the stacklayout
>>>that does work quite well. Setting visibility also does not work since
>>>the object is actually there and it is just not displayed.
>>
>>As far as i know, stacklayout layouts components in a single stack.
>>that is, you can only have at most 1 control (could be a composite)
>>visible at any time... its pretty useless when you want to hide
>>just part of your composite.
>>
>
>
>
Previous Topic:Wizard with 2 pages: how can I get information of the first page ?
Next Topic:KTable remove row
Goto Forum:
  


Current Time: Sun Oct 25 17:49:01 GMT 2020

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

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

Back to the top