4.18. Common Component Features

4.18.1. Sizing Components through Sizeable interface

IT Mill Toolkit components are sizeable; not in the sense that they were fairly large or that the number of the components and their features are sizeable, but in the sense that you can make them fairly large on the screen if you like. Or small, or whatever size.

The Sizeable interface, shared by all components, provides a number of manipulation methods and constants for setting the height and width of a component in absolute or relative units, or for leaving the size undefined.

The size of a component can be set with setWidth() and setHeight() methods. The methods take the size as a floating-point value. You need to give the unit of the measure as the second parameter for the above methods. The available units are listed in Table 4.6, “Size Units” below.

mycomponent.setWidth(100, Sizeable.UNITS_PERCENTAGE);
mycomponent.setWidth(400, Sizeable.UNITS_PIXELS);

Alternatively, you can speficy the size as a string. The format of such a string must follow the HTML/CSS standards for specifying measures.

mycomponent.setWidth("100%");
mycomponent.setHeight("400px");

The "100%" percentage value makes the component take all available size in the particular direction (see the description of Sizeable.UNITS_PERCENTAGE in the table below). You can also use the shorthand method setSizeFull() to set the size to 100% in both directions.

The size can be undefined in either or both dimensions, which means that the component will take the minimum necessary space. Most components have undefined size by default, but some layouts have full size in horizontal direction. You can set the height or width as undefined with Sizeable.SIZE_UNDEFINED parameter for setWidth() and setHeight().

You always need to keep in mind that a layout with undefined size may not contain components with defined relative size, such as "full size". See Section 5.3.1, “Layout Size” for details.

The following table lists the available units and their codes.

Table 4.6. Size Units

Sizeable.UNITS_PIXELSpxThe pixel is the basic hardware-specific measure of one physical display pixel.
Sizeable.UNITS_POINTSptThe point is a typographical unit, which is usually defined as 1/72 inches or about 0.35 mm. However, on displays the size can vary significantly depending on display metrics.
Sizeable.UNITS_PICASpcThe pica is a typographical unit, defined as 12 points, or 1/7 inches or about 4.233 mm. On displays, the size can vary depending on display metrics.
Sizeable.UNITS_EMemA unit relative to the used font, the width of the upper-case "M" letter.
Sizeable.UNITS_EXexA unit relative to the used font, the height of the lower-case "x" letter.
Sizeable.UNITS_MMmmA physical length unit, millimeters on the surface of a display device. However, the actual size depends on the display, its metrics in the operating system, and the browser.
Sizeable.UNITS_CMcmA physical length unit, centimeters on the surface of a display device. However, the actual size depends on the display, its metrics in the operating system, and the browser.
Sizeable.UNITS_INCHinA physical length unit, inches on the surface of a display device. However, the actual size depends on the display, its metrics in the operating system, and the browser.
Sizeable.UNITS_PERCENTAGE%A relative percentage of the available size. For example, for the top-level layout 100% would be the full width or height of the browser window. The percentage value must be between 0 and 100.

If a component inside HorizontalLayout or VerticalLayout has full size in the namesake direction of the layout, the component will expand to take all available space not needed by the other components. See Section 5.3.1, “Layout Size” for details.