Introduction

Welcome to PXElasticLayout . PXElasticLayout is my idea of a powerful and flexible layout manager.

Layout managers are a fundamental part of the Java(TM) GUI system. If you need more information on layout managers, please read this FAQ on what layout managers are .

The Simplest Example

With code like this ...

  private void init() {
    // initializing the components:
    nameLabel = new JLabel();
    nameLabel.setText("Name:");
    nameTextField = new JTextField();
    nameTextField.setColumns(20);
    firstNameLabel = new JLabel();
    firstNameLabel.setText("First name:");
    firstNameTextField = new JTextField();
    firstNameTextField.setColumns(20);

    // configuring the panel's layout:
    setLayout(new PXElasticLayout(8, 8, 14, 14));
    PXElasticConstraints constraints = new PXElasticConstraints();
    add(nameLabel, constraints);
    add(nameTextField, constraints.nextColumn());
    add(firstNameLabel, constraints.nextRow());
    add(firstNameTextField, constraints.nextColumn());
  }

... you get a panel like this (here used as a content pane):

Screenshot of the Simplest Layout Example

Ok, that is not much of a dialog. It was meant to be a simple example. Please refer to this site to see this example explained .

Why did I develop PXElasticLayout ?

If you are to program a complex layout like that of a usual input dialog using a layout manager of the JDK you do not come around GridBagLayout . There are a lot of layout managers around the world, of course (this site shows an overview of some layout managers ). They could help you, but often they lack flexibility. GridBagLayout has one major problem: "Specifying weights is an art that can have a significant impact on the appearance of the components a GridBagLayout controls," says The Java Tutorial. It seems I am no artist.

I thought of a layout manager similar to GridBagLayout , but I wanted the properties weightx and weighty to be used easier and the constraints object more comfortable to adjust - PXElasticLayout was born.

Why would you want to use it?

You would want to use PXElasticLayout because

  • it is easy to use ,
  • it is flexible ,
  • it is predictable , and
  • its layout code is readable .

What can it do for you?

PXElasticLayout is a layout manager for tabular layouts. Setting up a tabular layout is easy. Think of an HTML table or a form template in a word processor.

The PXElasticConstraints make it very easy and fast to implement a layout - you can reuse the same PXElasticConstraints object for every component you want to add to a container; methods like nextColumn and nextRow help with positioning components.

PXElasticLayout enables you to set up rudimentary spacing between components and at the border of the container. Just set up the spacing with one of the constructors or the corresponding setter methods.

Modern graphical user interfaces get more and more flexible. Think of split panes and resizable dialogs. But with most layout managers its difficult to program such a layout. PXElasticLayout is designed to make this easy. PXElasticLayout is capable of handling stretching and shrinking of the managed container differently - instead of weightx there is stretchX and shrinkX , weighty is split up to stretchY and shrinkY .

PXElasticConstraints ' limitPolicy can be used to specify what PXElasticLayout does when the minimum or maximum size of a component is reached.

The property fill of the PXElasticConstraints offers more possibilities than that of GridBagLayout .

PXElasticLayout has a lot more to offer, just have a look at the two minute tutorial .

Licensing

PXElasticLayout is licensed under the GNU Lesser General Public License . You may use it in free as well as in commercial software.