Controlling Sizing of Widgets with RowLayout

Another useful setting of RowLayout is pack. pack controls the initial sizing of widgets placed in the container. A setting of true allows RowLayout to create widgets of different sizes, depending on the widget type and the text setting of the widgets. The effect is seen in Figure 9-4, where each widget has a different size. The size of the Button widgets is controlled by the text each contains, hence the Cancel button is larger than the OK button.

Your interface design may require that you force all widgets in a row to be the same size, no matter what their style or contents.

How do I do that?

As with the wrap setting, you directly access the pack setting field by:

rl.pack = false;

Adding this line to RowLayoutExample creates Figure 9-7 when executed.

RowLayout with pack = false

Figure 9-7. RowLayout with pack = false

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.