Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » FormLayout -- how do children request space?
FormLayout -- how do children request space? [message #452732] Thu, 24 March 2005 00:53 Go to next message
Eclipse UserFriend
Originally posted by: doug-list.threepenny.net

I have a FormLayout that contains two windows. One is a vertical column
of buttons in a RowLayout(). The two are connected by:
rightData.left = new FormAttachment(buttons);

This creates a form with enough space for a single column of buttons.
The problem comes if I resize the display so that two columns are
required the space for the buttons doesn't increase.

Clearly there's some way to say "give me my computeSize()" amount of
space now that things have changed. I've tried calling layout(true) on
every window I can think of but no luck.

Can anyone put me straight on this? I'm sure it's pretty elementary.

Thanks,

Doug
Re: FormLayout -- how do children request space? [message #453027 is a reply to message #452732] Wed, 30 March 2005 00:45 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Do you need use FormAttachment (int, int) which allows an edge to be placed
at a percentage of the parent?

"Doug Pearson" <doug-list@threepenny.net> wrote in message
news:d1t7s6$r3f$1@news.eclipse.org...
> I have a FormLayout that contains two windows. One is a vertical column
> of buttons in a RowLayout(). The two are connected by:
> rightData.left = new FormAttachment(buttons);
>
> This creates a form with enough space for a single column of buttons.
> The problem comes if I resize the display so that two columns are
> required the space for the buttons doesn't increase.
>
> Clearly there's some way to say "give me my computeSize()" amount of
> space now that things have changed. I've tried calling layout(true) on
> every window I can think of but no luck.
>
> Can anyone put me straight on this? I'm sure it's pretty elementary.
>
> Thanks,
>
> Doug
>
Re: FormLayout -- how do children request space? [message #453290 is a reply to message #453027] Mon, 04 April 2005 19:23 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
You need to set the data.width hint as shown below. I thought in 3.1 this
would no longer be required but this seems to be a case were it still is. I
am investigating.

public static void main (String [] args) {
Display display = new Display ();
final Shell shell = new Shell (display);
shell.setLayout(new FormLayout());
final Composite c = new Composite(shell, SWT.BORDER);
c.setLayout(new RowLayout(SWT.VERTICAL));
for (int i = 0; i < 20; i++) {
Button b = new Button(c, SWT.PUSH);
b.setText("Button "+i);
}
Button b = new Button(shell, SWT.PUSH);
b.setText("Right");
FormData data = new FormData();
data.left = new FormAttachment(0, 5);
data.top = new FormAttachment(0, 5);
data.bottom = new FormAttachment(100, -5);
c.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(c, 5);
data.right = new FormAttachment(100, -5);
data.top = new FormAttachment(0, 5);
data.bottom = new FormAttachment(100, -5);
b.setLayoutData(data);
shell.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
Rectangle area = shell.getClientArea();
FormData data = (FormData)c.getLayoutData();
data.width = c.computeSize(-1, area.height - 10).x;
shell.layout(true);
}
});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}


"Steve Northover" <steve_northover@ca.ibm.com> wrote in message
news:d2cssi$4oo$1@news.eclipse.org...
> Do you need use FormAttachment (int, int) which allows an edge to be
> placed
> at a percentage of the parent?
>
> "Doug Pearson" <doug-list@threepenny.net> wrote in message
> news:d1t7s6$r3f$1@news.eclipse.org...
>> I have a FormLayout that contains two windows. One is a vertical column
>> of buttons in a RowLayout(). The two are connected by:
>> rightData.left = new FormAttachment(buttons);
>>
>> This creates a form with enough space for a single column of buttons.
>> The problem comes if I resize the display so that two columns are
>> required the space for the buttons doesn't increase.
>>
>> Clearly there's some way to say "give me my computeSize()" amount of
>> space now that things have changed. I've tried calling layout(true) on
>> every window I can think of but no luck.
>>
>> Can anyone put me straight on this? I'm sure it's pretty elementary.
>>
>> Thanks,
>>
>> Doug
>>
>
>
Re: FormLayout -- how do children request space? [message #453292 is a reply to message #453290] Mon, 04 April 2005 19:32 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
In 3.1, we handle the case where height = f(width). For example, a label
that wraps - the height varies as the width changes. This is also the case
of a RowLayout that is horizontal.

In your case you have width = f(height), the vertical RowLayout width varies
as the height changes. This case is not handled by the FormLayout (or
GridLayout) in 3.1.

"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:d2s4eo$gi0$1@news.eclipse.org...
> You need to set the data.width hint as shown below. I thought in 3.1 this
> would no longer be required but this seems to be a case were it still is.
> I am investigating.
>
> public static void main (String [] args) {
> Display display = new Display ();
> final Shell shell = new Shell (display);
> shell.setLayout(new FormLayout());
> final Composite c = new Composite(shell, SWT.BORDER);
> c.setLayout(new RowLayout(SWT.VERTICAL));
> for (int i = 0; i < 20; i++) {
> Button b = new Button(c, SWT.PUSH);
> b.setText("Button "+i);
> }
> Button b = new Button(shell, SWT.PUSH);
> b.setText("Right");
> FormData data = new FormData();
> data.left = new FormAttachment(0, 5);
> data.top = new FormAttachment(0, 5);
> data.bottom = new FormAttachment(100, -5);
> c.setLayoutData(data);
> data = new FormData();
> data.left = new FormAttachment(c, 5);
> data.right = new FormAttachment(100, -5);
> data.top = new FormAttachment(0, 5);
> data.bottom = new FormAttachment(100, -5);
> b.setLayoutData(data);
> shell.addListener(SWT.Resize, new Listener() {
> public void handleEvent(Event e) {
> Rectangle area = shell.getClientArea();
> FormData data = (FormData)c.getLayoutData();
> data.width = c.computeSize(-1, area.height - 10).x;
> shell.layout(true);
> }
> });
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
>
>
> "Steve Northover" <steve_northover@ca.ibm.com> wrote in message
> news:d2cssi$4oo$1@news.eclipse.org...
>> Do you need use FormAttachment (int, int) which allows an edge to be
>> placed
>> at a percentage of the parent?
>>
>> "Doug Pearson" <doug-list@threepenny.net> wrote in message
>> news:d1t7s6$r3f$1@news.eclipse.org...
>>> I have a FormLayout that contains two windows. One is a vertical column
>>> of buttons in a RowLayout(). The two are connected by:
>>> rightData.left = new FormAttachment(buttons);
>>>
>>> This creates a form with enough space for a single column of buttons.
>>> The problem comes if I resize the display so that two columns are
>>> required the space for the buttons doesn't increase.
>>>
>>> Clearly there's some way to say "give me my computeSize()" amount of
>>> space now that things have changed. I've tried calling layout(true) on
>>> every window I can think of but no luck.
>>>
>>> Can anyone put me straight on this? I'm sure it's pretty elementary.
>>>
>>> Thanks,
>>>
>>> Doug
>>>
>>
>>
>
>
Re: FormLayout -- how do children request space? [message #453293 is a reply to message #453292] Mon, 04 April 2005 19:33 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
By "not handled", I mean you must set the data.width in the resize event of
the parent as shown in my previous example.

"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:d2s4u4$h7q$1@news.eclipse.org...
> In 3.1, we handle the case where height = f(width). For example, a label
> that wraps - the height varies as the width changes. This is also the
> case of a RowLayout that is horizontal.
>
> In your case you have width = f(height), the vertical RowLayout width
> varies as the height changes. This case is not handled by the FormLayout
> (or GridLayout) in 3.1.
>
> "Veronika Irvine" <veronika_irvine@oti.com> wrote in message
> news:d2s4eo$gi0$1@news.eclipse.org...
>> You need to set the data.width hint as shown below. I thought in 3.1
>> this would no longer be required but this seems to be a case were it
>> still is. I am investigating.
>>
>> public static void main (String [] args) {
>> Display display = new Display ();
>> final Shell shell = new Shell (display);
>> shell.setLayout(new FormLayout());
>> final Composite c = new Composite(shell, SWT.BORDER);
>> c.setLayout(new RowLayout(SWT.VERTICAL));
>> for (int i = 0; i < 20; i++) {
>> Button b = new Button(c, SWT.PUSH);
>> b.setText("Button "+i);
>> }
>> Button b = new Button(shell, SWT.PUSH);
>> b.setText("Right");
>> FormData data = new FormData();
>> data.left = new FormAttachment(0, 5);
>> data.top = new FormAttachment(0, 5);
>> data.bottom = new FormAttachment(100, -5);
>> c.setLayoutData(data);
>> data = new FormData();
>> data.left = new FormAttachment(c, 5);
>> data.right = new FormAttachment(100, -5);
>> data.top = new FormAttachment(0, 5);
>> data.bottom = new FormAttachment(100, -5);
>> b.setLayoutData(data);
>> shell.addListener(SWT.Resize, new Listener() {
>> public void handleEvent(Event e) {
>> Rectangle area = shell.getClientArea();
>> FormData data = (FormData)c.getLayoutData();
>> data.width = c.computeSize(-1, area.height -
>> 10).x;
>> shell.layout(true);
>> }
>> });
>> shell.open ();
>> while (!shell.isDisposed ()) {
>> if (!display.readAndDispatch ()) display.sleep ();
>> }
>> display.dispose ();
>> }
>>
>>
>> "Steve Northover" <steve_northover@ca.ibm.com> wrote in message
>> news:d2cssi$4oo$1@news.eclipse.org...
>>> Do you need use FormAttachment (int, int) which allows an edge to be
>>> placed
>>> at a percentage of the parent?
>>>
>>> "Doug Pearson" <doug-list@threepenny.net> wrote in message
>>> news:d1t7s6$r3f$1@news.eclipse.org...
>>>> I have a FormLayout that contains two windows. One is a vertical
>>>> column
>>>> of buttons in a RowLayout(). The two are connected by:
>>>> rightData.left = new FormAttachment(buttons);
>>>>
>>>> This creates a form with enough space for a single column of buttons.
>>>> The problem comes if I resize the display so that two columns are
>>>> required the space for the buttons doesn't increase.
>>>>
>>>> Clearly there's some way to say "give me my computeSize()" amount of
>>>> space now that things have changed. I've tried calling layout(true) on
>>>> every window I can think of but no luck.
>>>>
>>>> Can anyone put me straight on this? I'm sure it's pretty elementary.
>>>>
>>>> Thanks,
>>>>
>>>> Doug
>>>>
>>>
>>>
>>
>>
>
>
Previous Topic:VT_SAFEARRAY support in SWT
Next Topic:SWT for Palm OS
Goto Forum:
  


Current Time: Sat Jul 20 01:26:29 GMT 2019

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

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

Back to the top