FormLayouts : Layout « SWT JFace Eclipse « Java






FormLayouts

FormLayouts
/******************************************************************************
 * All Right Reserved. 
 * Copyright (c) 1998, 2004 Jackwind Li Guojie
 * 
 * Created on 2004-6-16 20:22:44 by JACK
 * $Id$
 * 
 *****************************************************************************/
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.ColumnLayout;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;

public class FormLayouts extends ApplicationWindow{
  FormToolkit toolkit;
  ScrolledForm form;

  /**
   * @param parentShell
   */
  public FormLayouts(Shell parentShell) {
    super(parentShell);
  }
  
  private void demoColumnLayout() {
    ColumnLayout layout = new ColumnLayout();
    layout.maxNumColumns = 4;
    form.getBody().setLayout(layout);
    
    Color color = form.getDisplay().getSystemColor(SWT.COLOR_YELLOW);

    Label label = null;
    for(int i=0; i<10; i++) {
      label = toolkit.createLabel(form.getBody(), "Text label #" + i);
    }
    
  }
  
  private void demoTableWrapLayout() {
    TableWrapLayout layout = new TableWrapLayout();
    layout.numColumns = 2;
    form.getBody().setLayout(layout);
    
    Color color = form.getDisplay().getSystemColor(SWT.COLOR_YELLOW);

    Label label = toolkit.createLabel(form.getBody(), "Some text spans over two columns in the first row.  ", SWT.WRAP);
    TableWrapData data = new TableWrapData();
    data.colspan = 2;
    label.setLayoutData(data);
    label.setBackground(color);
    
    label = toolkit.createLabel(form.getBody(), "Some text in the first column of the second row. and here is goes on and on ... ... ... ... ", SWT.WRAP);
    label.setBackground(color);
    label = toolkit.createLabel(form.getBody(), "Some text in the second column of the second row. ", SWT.WRAP);
    label.setBackground(color);
  }
  

  /*
   * (non-Javadoc)
   * 
   * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
   */
  protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new FillLayout());

    // Sets up the toolkit.
    toolkit = new FormToolkit(getShell().getDisplay());

    // Creates a form instance.
    form = toolkit.createScrolledForm(composite);
    form.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Sets title.
    form.setText("Form Layouts Demo");

    // demoTableWrapLayout();
    demoColumnLayout();

    return composite;
  }

  public static void main(String[] args) {
    FormLayouts win = new FormLayouts(null);
    win.setBlockOnOpen(true);

    win.open();
  }

}


           
       








Related examples in the same category

1.SWT Layout Example in OneSWT Layout Example in One
2.SWT GridLayout DemoSWT GridLayout Demo
3.SWT GridLayoutSWT GridLayout
4.Control Size LocationControl Size Location
5.SWT RowLayout SampleSWT RowLayout Sample
6.SWT FillLayout SampleSWT FillLayout Sample
7.SWT Form Layout SampleSWT Form Layout Sample
8.SWT GridLayout SampleSWT GridLayout Sample
9.GridLayout Sample Grab SpaceGridLayout Sample Grab Space
10.Grid Layout SpanGrid Layout Span
11.Layout ComponentsLayout Components
12.Layout TermsLayout Terms
13.StackLayout SampleStackLayout Sample
14.BorderLayout SampleBorderLayout Sample
15.FormLayout SimpleFormLayout Simple
16.A BorderLayoutA BorderLayout
17.FillLayout HorizontalFillLayout Horizontal
18.FillLayout VerticalFillLayout Vertical
19.FormLayout ComplexFormLayout Complex
20.FormLayout Form AttachmentFormLayout Form Attachment
21.FormLayoutFormLayout
22.GridLayout 2x2GridLayout 2x2
23.Grid Layout ComplexGrid Layout Complex
24.No LayoutNo Layout
25.Row Layout TestRow Layout Test
26.Stack Layout TestStack Layout Test
27.Row Layout HorizontalRow Layout Horizontal
28.FillLayout ExampleFillLayout Example
29.FormLayout ExampleFormLayout Example
30.GridLayout ExampleGridLayout Example
31.GridLayout Example 2GridLayout Example 2
32.Layout ExampleLayout Example
33.RowLayout ExampleRowLayout Example
34.SWT FillLayout
35.SWY Radial Layout
36.Use of Radial Layout
37.GridLayout with All Options
38.Simplest GridLayout
39.SWT GridLayout: GridSpan
40.SWT RowLayout
41.SWT FillLayout Composite
42.SWT GridLayout: align widgets in a vertical columnSWT GridLayout: align widgets in a vertical column
43.SWT GridLayout: align widgets in a horizontal rowSWT GridLayout: align widgets in a horizontal row
44.Exclude a widget from a GridLayoutExclude a widget from a GridLayout
45.Insert widgets into a grid layoutInsert widgets into a grid layout
46.Align widgets in a GridLayoutAlign widgets in a GridLayout
47.FormLayout: create a simple OK and CANCEL dialog using form layoutFormLayout: create a simple OK and CANCEL dialog using form layout
48.FormLayout: center a label and single line text using a form layoutFormLayout: center a label and single line text using a form layout
49.FormLayout: create a simple dialog using form layoutFormLayout: create a simple dialog using form layout