Java Deep

Pure Java, what else

About

javax0 is a technical Java oriented blog. Whenever I find something interesting, in the mood and feel the power to publish it, you will get it here. Publications are usually released on Wednesday 15:00am GMT.

One response to “About

  1. Birke Heeren July 5, 2014 at 11:22 am

    Dear Mr. Verhas,

    for a Java project with forms and datamasks, I needed a layoutmanager für Swing, that resizes responsively to the space available. The layout was supposed to look neat and the code necessary, too. I wanted to be able to set the minimum and maximum size of each component.

    Since I could not find such a layoutmanager, I wrote one: TOnionLayout. This layout consists of two layoutmanagers:
    TrainLayout: a row of components from left to right with equal height and individual width.
    Totemlayout: a column of components from top to bottom with equal width and individual height.
    Both layoutmanagers can be stacked into each other (like the layers of an onion). TOnionLayout can also be placed into a JScrollPane. In case the window is made smaller, the TOnionLayout will get smaller, too, down to its minimum size. Only when space decreases further the scrollbars appear.

    For all first inner objects of a TOnionLayout it is possible to set minimum and maximum sizes. Without these the space is spread evenly. It is also possible to mix objects with sizes set and without sizes set.
    JButtons should be placed into a JPanel with FlowLayout, and the minimum and maximum sizes should be set on the JPanel.
    JTables should be placed into a JPanel with BorderLayout, into the CENTER component. Also the sizes should be set on the JPanel.

    The minimum and maximum sizes set in a TOnionLayout only have to fit together approximately. The exact alignment is done by the layout. Errors in sizes, are automaically adjusted. In case a minimum is larger than a maximum, maximum = minimum ist set. If the test classes TrainLayoutTest and TotemLayoutTest are used the errors are displayed on the console.
    In case a TOnion layer is sometimes filled and sometimes empty, it is possible to set minimum and maximum sizes on that layer also. These sizes are used only, when the layer is in its empty state.

    Coding with TOnionLayout produces neat code that can be easily managed. The layout is therefore fit to be used by Java beginners.

    The trick of TOnionLayout is, that even though the layout is done topdown, each layer inquires about the minimum and maximum sizes of all its contents. To get a good performance these sizes are cached. Only when adding or deleting a component the sizes of that layer and all layers outwards are recalculated.

    Please feel free to download and test TOnion layout. I appreciate if you write about this layout, for many people to profit from my work.

    Best regards,
    Birke Heeren

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: