Changing parent of widgets problem [message #534178] |
Tue, 18 May 2010 09:47 |
Geejay 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 |
Thomas Schindl Messages: 6651 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 |
Geejay 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);
>>
>> }
>
|
|
|
Powered by
FUDForum. Page generated in 0.03430 seconds