Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Changing parent of widgets problem
Changing parent of widgets problem [message #534178] Tue, 18 May 2010 09:47 Go to next message
Geejay is currently offline GeejayFriend
Messages: 160
Registered: February 2010
Senior Member
Hello peoples,

I am trying to change (at runtime) the parent of a widget.

Use case (not saying yet whether runtime switching is the correct approach):
Build up a set of widgets, and then move them arôund according to the
desired view.

Wondering why the below code doesn't work? Specifically, when I hit the
"change parent" button, the labels just disappear (even though isVisible()
returns true).

public void createPartControl(Composite parent) {
Composite master = new Composite(parent, SWT.NONE);
master.setLayout(new GridLayout(2, false));

shell1 = new Composite(master, SWT.NONE);
shell1.setLayout(new FillLayout(SWT.VERTICAL));

shell2 = new Composite(master, SWT.NONE);
shell2.setLayout(new FillLayout(SWT.VERTICAL));

Button change = new Button(shell1, SWT.NONE);
change.setText("change parent");
change.addSelectionListener(this);

lbl = new Label(shell1, SWT.NONE);
lbl.setText("start in shell1:reparentable?" + lbl.isReparentable());

lbl2 = new Label(shell2, SWT.NONE);
lbl2.setText("start in shell2");
}

@Override
public void widgetSelected(SelectionEvent e) {
if (lbl.getParent() == shell1)
lbl.setParent(shell2);
else
lbl.setParent(shell1);
if (lbl2.getParent() == shell1)
lbl2.setParent(shell2);
else
lbl2.setParent(shell1);
lbl.setVisible(true);
lbl2.setVisible(true);

}
Re: Changing parent of widgets problem [message #534202 is a reply to message #534178] Tue, 18 May 2010 10:46 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6499
Registered: July 2009
Senior Member
I think you should issue a layout() on the shells after having reparented

Tom

Am 18.05.10 11:47, schrieb geejay:
> Hello peoples,
>
> I am trying to change (at runtime) the parent of a widget.
>
> Use case (not saying yet whether runtime switching is the correct
> approach): Build up a set of widgets, and then move them arôund
> according to the desired view.
>
> Wondering why the below code doesn't work? Specifically, when I hit the
> "change parent" button, the labels just disappear (even though
> isVisible() returns true).
>
> public void createPartControl(Composite parent) {
> Composite master = new Composite(parent, SWT.NONE);
> master.setLayout(new GridLayout(2, false));
>
> shell1 = new Composite(master, SWT.NONE);
> shell1.setLayout(new FillLayout(SWT.VERTICAL));
>
> shell2 = new Composite(master, SWT.NONE);
> shell2.setLayout(new FillLayout(SWT.VERTICAL));
>
> Button change = new Button(shell1, SWT.NONE);
> change.setText("change parent");
> change.addSelectionListener(this);
>
> lbl = new Label(shell1, SWT.NONE);
> lbl.setText("start in shell1:reparentable?" + lbl.isReparentable());
>
> lbl2 = new Label(shell2, SWT.NONE);
> lbl2.setText("start in shell2");
> }
>
> @Override
> public void widgetSelected(SelectionEvent e) {
> if (lbl.getParent() == shell1)
> lbl.setParent(shell2);
> else
> lbl.setParent(shell1);
> if (lbl2.getParent() == shell1)
> lbl2.setParent(shell2);
> else
> lbl2.setParent(shell1);
> lbl.setVisible(true);
> lbl2.setVisible(true);
>
> }
Re: Changing parent of widgets problem [message #534219 is a reply to message #534202] Tue, 18 May 2010 11:51 Go to previous message
Geejay is currently offline GeejayFriend
Messages: 160
Registered: February 2010
Senior Member
Thanks Tom, yes, that worked simply calling shell.layout(). Thanks again!

"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:hstr6k$559$1@build.eclipse.org...
> I think you should issue a layout() on the shells after having reparented
>
> Tom
>
> Am 18.05.10 11:47, schrieb geejay:
>> Hello peoples,
>>
>> I am trying to change (at runtime) the parent of a widget.
>>
>> Use case (not saying yet whether runtime switching is the correct
>> approach): Build up a set of widgets, and then move them arôund
>> according to the desired view.
>>
>> Wondering why the below code doesn't work? Specifically, when I hit the
>> "change parent" button, the labels just disappear (even though
>> isVisible() returns true).
>>
>> public void createPartControl(Composite parent) {
>> Composite master = new Composite(parent, SWT.NONE);
>> master.setLayout(new GridLayout(2, false));
>>
>> shell1 = new Composite(master, SWT.NONE);
>> shell1.setLayout(new FillLayout(SWT.VERTICAL));
>>
>> shell2 = new Composite(master, SWT.NONE);
>> shell2.setLayout(new FillLayout(SWT.VERTICAL));
>>
>> Button change = new Button(shell1, SWT.NONE);
>> change.setText("change parent");
>> change.addSelectionListener(this);
>>
>> lbl = new Label(shell1, SWT.NONE);
>> lbl.setText("start in shell1:reparentable?" + lbl.isReparentable());
>>
>> lbl2 = new Label(shell2, SWT.NONE);
>> lbl2.setText("start in shell2");
>> }
>>
>> @Override
>> public void widgetSelected(SelectionEvent e) {
>> if (lbl.getParent() == shell1)
>> lbl.setParent(shell2);
>> else
>> lbl.setParent(shell1);
>> if (lbl2.getParent() == shell1)
>> lbl2.setParent(shell2);
>> else
>> lbl2.setParent(shell1);
>> lbl.setVisible(true);
>> lbl2.setVisible(true);
>>
>> }
>
Previous Topic:CCombo: dropdown seems to be a little too "autonomous"
Next Topic:Scrollbar not appearing at startup
Goto Forum:
  


Current Time: Tue Aug 20 13:38:46 GMT 2019

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

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

Back to the top