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 |
Eclipse User |
|
|
|
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 #453290 is a reply to message #453027] |
Mon, 04 April 2005 19:23 |
Veronika Irvine 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 |
Veronika Irvine 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 |
Veronika Irvine 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
>>>>
>>>
>>>
>>
>>
>
>
|
|
|
Goto Forum:
Current Time: Thu Sep 26 10:23:09 GMT 2024
Powered by FUDForum. Page generated in 0.04224 seconds
|