The SWT FormLayout

When an interface is designed to allow for data input from a user, it is usually best to design that interface as a form. The SWT FormLayout is designed to allow for easy programming of forms. Using FormLayout you pin widgets to a particular position on the window, specifying the height and width of the widget either in pixels or as a percentage of the total container height and width.

FormLayout is the most powerful of the layout classes as far as what it can do for you, but that power comes at the price of having even more classes and settings to deal with when creating the desired physical layout. With FillLayout, you need only manage style settings and no additional supporting classes. RowLayout added new settings and an optional RowData class that is seldom used. With GridLayout comes many additional settings and a GridData class that, although not mandatory, is required to provide a fully functional GridLayout.

With FormLayout there is even more to configure, including two helper classes—FormData and FormAttachment. Unlike with GridLayout, where use of GridData was optional, use of FormData and FormAttachment is mandatory. Failure to use the FormData class, for example, causes all widgets to be stacked on top of each other in the same space on the container.

Get SWT: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.