© www.cellspark.com - All products | Download | Contact

EquitySoft graphic

VerticalLayout is, as the name suggests, a layout manager that arranges components vertically as opposed to horizontally. GridBagLayout will also do the job but VerticalLayout is much easier to use. The Swing BoxLayout also does vertical layouts but components will often be expanded when you don't want them to be (it was frustration with BoxLayout that led to VerticalLayout being written). Like FlowLayout, VerticalLayout doesn't try to expand components to fit the display area although it can be told to expand components horizontally to fill the available space. This means that VerticalLayout is a good alternative to GridLayout without the restriction that each component be the same size. Unlike FlowLayout it won't form a new column when it runs out of space. VerticalLayout is open source based on the General Public License.

Also included with VerticalLayout is the source for ProportionalLayout. This layout manager allows components to be aligned horizontally but the space to be allocated according to a given set of porportions. Again this is possible with GridBagLayout but ProportionalLayout solves the resizing problems that can be encountered when using GridBagLayout with JSplitPane in which sudden jumps in component proportions can be seen.

Links for VerticalLayout are:

If you choose to use the code commercially or non-commercially some mention of the author's name in your documentation is all that is expected. The uncompressed class file size is 3K which means inclusion of the code in an applet is not out of the question. Below are some screenshot examples of what it does.

Here are three buttons arranged with the default settings for VerticalLayout. They are anchored to the top of the display area and centered horizontally with a gap of 5 pixels between them. The anchor point, the horizontal justification and the vertical gap are the three variables that can be set when creating an instance of the class.

The next example has the anchor point set to CENTER and the horizontal alignment is RIGHT. The vertical gap is set to 10 pixels.

Lastly the anchor is set as the BOTTOM of the display area with the horizontal alignment set to BOTH so the components spread horizontally. The vertical gap is set to 0 pixels.