Constructing SWT Layouts
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
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