You are here

Tetris Layout

Welcome to Tetris Layout project

TetrisLayout is a mature project implementing a new Java layout. Previously provided as a standalone library it is now a module of the Kinetic Models framework; it can still be used as an independent library.

With TetrisLayout you can

  • create variable grid layout with variable gaps between components;
  • span components between multiple rows and colums;
  • assign different weights to rows and columns;
  • set absolute startup sizes to rows and columns;
  • set custom startup sizes to rows and columns using Connectors;
  • implement custom layout algorithms;
  • fill and anchor a component in a grid cell in many different ways.

In addition a transparent component panel is provided to debug the layout structure at run-time as shown by the following pictures.


Anchor and fill test
BorderLayout simulation
GridLayout simulation
Horizontal pack test
Nested layout test
Power grid
Simple form test
Variable gap test
Variable grid layout test
Vortex grid test
Vertical pack test


The following picture displays an example of component column size calculation while the main window is resized. The algorithm works with minimum, preferred and maximum size of a component and is applied in row size calculation as well.

The example shows a simple layout containing two component laid out on two columns.

The two component have the same size so they could be virtually expanded and squashed maintaining the same column width proportion between them.

At the beginning the main window size is calculated summing the preferred column size of the two components. This situation is highlighted by the blue vertical line.

Components have minimum and maximum length defined: if the main window is expanded, the two columns expand proportionally until column A reach the maximum size. At that point the weight of column A is distributed on the remaining expanding columns, in this case just column B.

When column B reaches the maximum size the main window can still be expanded but the two columns don't change any more.

The same concept is applied when the main window is squashed. In the example column B preferred and minimum sizes are the same and column B cannot be squashed. The weight of column B is the redistributed on the remaining resizing column, in this case column A.

When column A reaches the minimum width too, the main window width can still be decreased but the size of both column don't change anymore.

The same picture is provided below in two different file formats.

TetrisLayout algorithm - OpenOffice

TetrisLayout algorithm - PDF