dcsimg
August 16, 2018
Hot Topics:

Constructing SWT Layouts

  • April 15, 2004
  • By Koray Guclu
  • Send Email »
  • More Articles »

FormLayout

FormLayout is a very flexible layout, like GridLayout, but it works in a completely different way. In GridLayout, you have to plan everything ahead and build your user interface. In contrast to GridLayout, FormLayout is independent from the complete layout. The position and size of the components depend on one Control.

The location of the properties listed in Table 6 can be seen in Figure 9.

FormData and FormAttachment

Each widget within a composite having FormLayout can have FormData to set the different layout properties for a widget.

The FormData object has the properties listed in Table 7.

A FormData object can have 0 or 4 FormAttachment objects. The form attachment can have controls (see Figure 15). The FormAttachment object can have the properties listed in Table 8.

Figure 14. FormLayout Example

The above example shows a form layout created by using the code snippet below.

 Source 7.  FormLayout example
  FormLayout layout= new FormLayout();
  shell.setLayout (layout);

  Button button1 = new Button(shell, SWT.PUSH);
  Button button2 = new Button(shell, SWT.PUSH);
  Button button3 = new Button(shell, SWT.PUSH);
  button1.setText("B1");
  button2.setText("B2");
  button3.setText("B3");

  FormData data1 = new FormData();
  data1 .left    = new FormAttachment(0,5);
  data1 .right   = new FormAttachment(25,0);
  button1.setLayoutData(data1);

  FormData data2 = new FormData();
  data2.left     = new FormAttachment(button1,5);
  data2.right    = new FormAttachment(90,-5);
  button2.setLayoutData(data2);

  FormData data3 = new FormData();
  data3.top      = new FormAttachment(button2,5);
  data3.bottom   = new FormAttachment(100,-5);
  data3.right    = new FormAttachment(100,-5);
  data3.left     = new FormAttachment(25,5);
  button3.setLayoutData(data3);

Figure 15 shows the location of the properties and location of the buttons.

Figure 15. FormLayout Example





Page 4 of 5



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

Thanks for your registration, follow us on our social networks to keep up-to-date