8. Layouts

This chapter covers each Layout in detail. For an explanation of how Layouts fit into the overall architecture of Metawidget, see Chapter 2, Architecture.

8.1 Desktop Layouts

Metawidget supports multiple Layouts for each desktop framework, targeting different arrangements within each environment.

8.1.1 Swing Layouts

BoxLayout

Layout to simply output components one after another, with no labels and no structure, using javax.swing.BoxLayout. This is like FlowLayout (below), except it fills width. It can be useful for JTable CellEditors (see Section 1.3.1, “Desktop Address Book”).

FlowLayout

Layout to simply output components one after another, with no labels and no structure, using java.awt.FlowLayout. This is like BoxLayout, except it does not fill width. It can be useful for button bars (see Section 1.3.1, “Desktop Address Book”).

GridBagLayout

Layout to arrange widgets using java.awt.GridBagLayout. Widgets are arranged in a table, with one column for the label and another for the widget. This Layout recognizes the following parameters, configured using GridBagLayoutConfig:

Property Description
labelAlignment Such as SwingConstants.LEFT or SwingConstants.RIGHT
labelFont Label font
labelForeground Label foreground color
labelSuffix Text to display after label text. Defaults to a colon (:)
numberOfColumns Number of columns. Each label/component pair is considered one column
requiredAlignment Alignment of the asterisk relative to the component. Can be SwingConstants.LEFT, SwingConstants.CENTER or SwingConstants.RIGHT
requiredText Text to display for required properties. Defaults to an asterisk
supportMnemonics Whether to convert &'s in labels into keyboard mnemonics

GroupLayout

Layout to arrange widgets using javax.swing.GroupLayout. Widgets are arranged in a table, with one column for the label and another for the widget.

MigLayout

Layout to arrange widgets using net.miginfocom.swing.MigLayout. Widgets are arranged in a table, with one column for the label and another for the widget. This Layout recognizes the following parameters, configured using MigLayoutConfig:

Property Description
numberOfColumns Number of columns. Each label/component pair is considered one column
supportMnemonics Whether to convert &'s in labels into keyboard mnemonics

SeparatorLayoutDecorator

LayoutDecorator to decorate widgets from different sections using a JSeparator. This LayoutDecorator recognizes the following parameters, configured using SeparatorLayoutDecoratorConfig:

Property Description
alignment One of SwingConstants.LEFT or SwingConstants.RIGHT.
layout Metawidget Layout to use for laying out the sections, for example org.metawidget.swing.layout.GridBagLayout.

TabbedPaneLayoutDecorator

LayoutDecorator to decorate widgets from different sections using a JTabbedPane. This LayoutDecorator recognizes the following parameters, configured using TabbedPaneLayoutDecoratorConfig:

Property Description
layout Metawidget Layout to use for laying out the sections, for example org.metawidget.swing.layout.GridBagLayout.
tabPlacement One of SwingConstants.TOP, SwingConstants.BOTTOM, SwingConstants.LEFT or SwingConstants.RIGHT as defined by JTabbedPane.setTabPlacement.

TitledPanelLayoutDecorator

LayoutDecorator to decorate widgets from different sections using a JPanel with a TitledBorder. This LayoutDecorator recognizes the following parameters, configured using LayoutDecoratorConfig:

Property Description
layout Metawidget Layout to use for laying out the sections, for example org.metawidget.swing.layout.GridBagLayout.

8.1.2 SWT Layouts

FillLayout

Layout to simply output components one after another, with no labels and no structure, using org.eclipse.swt.layout.FillLayout. This is like RowLayout, except it fills width. It can be useful for Table Editors (see Section 1.3.1, “Desktop Address Book”).

GridLayout

Layout to arrange widgets using org.eclipse.swt.layout.GridLayout. Widgets are arranged in a table, with one column for the label and another for the widget. This Layout recognizes the following parameters, configured using GridLayoutConfig:

Property Description
labelAlignment Such as SWT.LEFT or SWT.RIGHT
labelFont Label font
labelForeground Label foreground color
labelSuffix Text to display after label text. Defaults to a colon (:)
numberOfColumns Number of columns. Each label/component pair is considered one column
requiredAlignment Alignment of the asterisk relative to the control. Can be SWT.LEFT or SWT.RIGHT
requiredText Text to display for required properties. Defaults to an asterisk

MigLayout

Layout to arrange widgets using net.miginfocom.swt.MigLayout. Widgets are arranged in a table, with one column for the label and another for the widget. This Layout recognizes the following parameters, configured using MigLayoutConfig:

Property Description
numberOfColumns Number of columns. Each label/component pair is considered one column

RowLayout

Layout to simply output components one after another, with no labels and no structure, using org.eclipse.swt.layout.RowLayout. This is like FillLayout, except it does not fill width. It can be useful for button bars (see Section 1.3.1, “Desktop Address Book”).

SeparatorLayoutDecorator

LayoutDecorator to decorate widgets from different sections using a Label( SWT.SEPARATOR ). This LayoutDecorator recognizes the following parameters, configured using SeparatorLayoutDecoratorConfig:

Property Description
alignment One of SWT.LEFT or SWT.RIGHT.
layout Metawidget Layout to use for laying out the sections, for example org.metawidget.swt.layout.GridLayout.

TabFolderLayoutDecorator

LayoutDecorator to decorate widgets from different sections using a TabFolder. This LayoutDecorator recognizes the following parameters, configured using TabFolderLayoutDecoratorConfig:

Property Description
layout Metawidget Layout to use for laying out the sections, for example org.metawidget.swt.layout.GridLayout.
tabLocation One of SWT.TOP or SWT.BOTTOM.