Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Help needed on FormAttachment
Help needed on FormAttachment [message #445377] |
Thu, 04 November 2004 16:26 |
Eclipse User |
|
|
|
Originally posted by: hortiz.xxx.com
Hi,
Here is a sample code to illustrate my problem : I use a FormLayout for my
main composite (the "red" one) and I create a new Composite (the "green"
one) in it, using a FormData.
My problem is that I want the green composite to be as wide as its parent
composite.
I've tried to set some FormAttachment but I didn't manage to find the
solution.
Could you please help me,
Thanks
H.ORTIZ
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FormAttachmentTest {
private static Display display;
private static Shell shell;
public static void main(String[] args) {
display = new Display ();
shell = new Shell (display);
shell.setBackground(new Color(display, new RGB(255,0,0)));
FormLayout formLayout = new FormLayout();
shell.setLayout(formLayout);
Composite composite = new Composite(shell, SWT.BORDER);
composite.setBackground(new Color(display, new RGB(0,255,0)));
FormData data = new FormData();
composite.setLayoutData(data);
shell.pack();
shell.setSize(800,600);
shell.open();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
display.dispose ();
}
}
|
|
|
Re: Help needed on FormAttachment [message #445387 is a reply to message #445377] |
Thu, 04 November 2004 18:20 |
Steve Northover Messages: 1636 Registered: July 2009 |
Senior Member |
|
|
You need to set the form attachments. In this case, why would you use a form
at all? Why not use a FillLayout?
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FormAttachmentTest {
private static Display display;
private static Shell shell;
public static void main(String[] args) {
display = new Display();
shell = new Shell(display);
shell.setBackground(new Color(display, new RGB(255, 0, 0)));
FormLayout formLayout = new FormLayout();
shell.setLayout(formLayout);
Composite composite = new Composite(shell, SWT.BORDER);
composite.setBackground(new Color(display, new RGB(0, 255, 0)));
FormData data = new FormData();
data.left = new FormAttachment (0);
data.right = new FormAttachment (100);
data.top = new FormAttachment (0);
data.bottom = new FormAttachment (100);
composite.setLayoutData(data);
shell.pack();
shell.setSize(800, 600);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
"HORTIZ" <hortiz@xxx.com> wrote in message news:cmdl6r$qgk$1@eclipse.org...
> Hi,
>
> Here is a sample code to illustrate my problem : I use a FormLayout for my
> main composite (the "red" one) and I create a new Composite (the "green"
> one) in it, using a FormData.
>
> My problem is that I want the green composite to be as wide as its parent
> composite.
>
> I've tried to set some FormAttachment but I didn't manage to find the
> solution.
>
> Could you please help me,
> Thanks
> H.ORTIZ
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.Color;
> import org.eclipse.swt.graphics.RGB;
> import org.eclipse.swt.layout.FormData;
> import org.eclipse.swt.layout.FormLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
> public class FormAttachmentTest {
>
> private static Display display;
> private static Shell shell;
>
> public static void main(String[] args) {
>
> display = new Display ();
> shell = new Shell (display);
>
> shell.setBackground(new Color(display, new RGB(255,0,0)));
> FormLayout formLayout = new FormLayout();
> shell.setLayout(formLayout);
>
> Composite composite = new Composite(shell, SWT.BORDER);
> composite.setBackground(new Color(display, new RGB(0,255,0)));
>
> FormData data = new FormData();
> composite.setLayoutData(data);
>
> shell.pack();
> shell.setSize(800,600);
> shell.open();
>
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ())
> display.sleep ();
> }
> display.dispose ();
> }
> }
>
>
>
>
|
|
| |
Re: Help needed on FormAttachment [message #445406 is a reply to message #445387] |
Fri, 05 November 2004 08:14 |
Eclipse User |
|
|
|
Originally posted by: hortiz.xxx.com
Hi Steve,
If I use a FormLayout it is because my composite is hidden / shown at
runtime so I have adapted the sample code provided by Caroline MacLeod at
https://bugs.eclipse.org/bugs/show_bug.cgi?id=49426
Steve Northover wrote:
> You need to set the form attachments. In this case, why would you use a form
> at all? Why not use a FillLayout?
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.Color;
> import org.eclipse.swt.graphics.RGB;
> import org.eclipse.swt.layout.FormAttachment;
> import org.eclipse.swt.layout.FormData;
> import org.eclipse.swt.layout.FormLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> public class FormAttachmentTest {
> private static Display display;
> private static Shell shell;
> public static void main(String[] args) {
> display = new Display();
> shell = new Shell(display);
> shell.setBackground(new Color(display, new RGB(255, 0, 0)));
> FormLayout formLayout = new FormLayout();
> shell.setLayout(formLayout);
> Composite composite = new Composite(shell, SWT.BORDER);
> composite.setBackground(new Color(display, new RGB(0, 255, 0)));
> FormData data = new FormData();
> data.left = new FormAttachment (0);
> data.right = new FormAttachment (100);
> data.top = new FormAttachment (0);
> data.bottom = new FormAttachment (100);
> composite.setLayoutData(data);
> shell.pack();
> shell.setSize(800, 600);
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
> "HORTIZ" <hortiz@xxx.com> wrote in message news:cmdl6r$qgk$1@eclipse.org...
>> Hi,
>>
>> Here is a sample code to illustrate my problem : I use a FormLayout for my
>> main composite (the "red" one) and I create a new Composite (the "green"
>> one) in it, using a FormData.
>>
>> My problem is that I want the green composite to be as wide as its parent
>> composite.
>>
>> I've tried to set some FormAttachment but I didn't manage to find the
>> solution.
>>
>> Could you please help me,
>> Thanks
>> H.ORTIZ
>>
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.graphics.Color;
>> import org.eclipse.swt.graphics.RGB;
>> import org.eclipse.swt.layout.FormData;
>> import org.eclipse.swt.layout.FormLayout;
>> import org.eclipse.swt.widgets.Composite;
>> import org.eclipse.swt.widgets.Display;
>> import org.eclipse.swt.widgets.Shell;
>>
>> public class FormAttachmentTest {
>>
>> private static Display display;
>> private static Shell shell;
>>
>> public static void main(String[] args) {
>>
>> display = new Display ();
>> shell = new Shell (display);
>>
>> shell.setBackground(new Color(display, new RGB(255,0,0)));
>> FormLayout formLayout = new FormLayout();
>> shell.setLayout(formLayout);
>>
>> Composite composite = new Composite(shell, SWT.BORDER);
>> composite.setBackground(new Color(display, new RGB(0,255,0)));
>>
>> FormData data = new FormData();
>> composite.setLayoutData(data);
>>
>> shell.pack();
>> shell.setSize(800,600);
>> shell.open();
>>
>> while (!shell.isDisposed ()) {
>> if (!display.readAndDispatch ())
>> display.sleep ();
>> }
>> display.dispose ();
>> }
>> }
>>
>>
>>
>>
|
|
|
Re: Help needed on FormAttachment [message #445408 is a reply to message #445388] |
Fri, 05 November 2004 08:18 |
Eclipse User |
|
|
|
Originally posted by: hortiz.xxx.com
Thanks a lot Stefan, it works fine now
Stefan Zeiger wrote:
> HORTIZ wrote:
>> Here is a sample code to illustrate my problem : I use a FormLayout for
>> my main composite (the "red" one) and I create a new Composite (the
>> "green" one) in it, using a FormData.
>> My problem is that I want the green composite to be as wide as its
>> parent composite.
> Here's the correct FormData:
>> FormData data = new FormData();
> data.left = new FormAttachment(0);
> data.right = new FormAttachment(100);
>> composite.setLayoutData(data);
|
|
|
Goto Forum:
Current Time: Thu Mar 28 19:28:24 GMT 2024
Powered by FUDForum. Page generated in 0.02479 seconds
|