Pagelayout continues to be the most frequently downloaded Java layout manager on Sourceforge. (It also appears to be, by far, the most popular of all projects in Sourceforge that only address the GUI Layout issues for Java applications.)
Latest release pagelayout1.16 (05/08/2008) fixes some minor bugs in the previous version. An accompanying application, Gola, which allows you to layout the components in a visual editor and automatically generate eminently readable Java code for use with the Pagelayout layout manager, has also been updated.
PageLayout is now also bundled with Mathnium , an interpreter written in Java. The scripting facilities of Mathnium can be used to rapidly prototype Java Swing GUI applications without significant effort.
PageLayout is a layout manager for Java Swing/AWT that encapsulates, in a single package, the functionality of many other layout managers. It allows you to lay out components in appropriately aligned rows, columns, and grids. The elements of rows, columns, and grids may themselves be rows, columns and grids of components. As a result, relatively complex layouts can be managed with code that is compact and conceptually quite straightforward to understand and, therefore, maintain.
For example, click to see the relatively small number of lines of PageLayout-specific code that are required to produce the GUI whose image follows. Other examples are available in Quickstart Examples and JavaDocs.
import javax.swing.*; import java.awt.geom.*; import java.awt.*; import pagelayout.*; import static pagelayout.EasyCell.*; public class Form extends JFrame { public Form() { // Create the grid CellGrid g=grid( //Row 1 createNamedSeparator("General"), span(),span(),span(),eol(), //Row 2 new JLabel("Company"),new JTextField(20), span(),span(),eol(), //Row 3 new JLabel("Contact"),new JTextField(20), span(),span(),eol(), //Row 4 vgap(10),span(),span(),span(),eol(), //Row 5 createNamedSeparator("Propeller"), span(),span(),span(),eol(), //Row 6 new JLabel("PTI[kW]"),new JTextField(10), new JLabel("Power[kW]"),new JTextField(10),eol(), //Row 7 new JLabel("R[mm]"),new JTextField(10), new JLabel("D[mm]"),new JTextField(10)); // For setting alignments of labels. // For simplicity we set all alignments to be the same. for(int i=0;i<7;i++) for(int j=0;j<4;j++)g.setAlignment(i,j,right,center); // Create the layout and set it to be the // layout of the content pane of the frame. g.createLayout(getContentPane()); pack(); setVisible(true); } // A composite separator with a name. public static Row createNamedSeparator(String text) { Row row=new Row(Cell.JUSTIFIED,Cell.CENTER); JLabel label=new JLabel(text); label.setForeground(Color.blue); row.add(label); JSeparator sep=new JSeparator(); row.add(sep); Dimension d=sep.getPreferredSize(); sep.setMaximumSize(new Dimension(Cell.MAX,d.height)); return row; } }
The code is simpler and more compact than what would be needed with most other layout managers. The added benefit of PageLayout is that there are hardly any new concepts other than those of rows, columns or grids to learn.
The image of the GUI produced by the code above.
On resizing, the editors and the separators change size,
and the relative spatial locations of the various components are preserved.
PageLayout generally requires the developer to think only in terms of simple geometrical concepts. There is almost never any need to explicitly use numerical values for the locations and the sizes of components or to specify which components should be allowed to grow or shrink as the window resizes. The main focus of the development of PageLayout has been on the implementation of a general geometrical algorithm for layout management, and the effort has yielded a framework which is comprehensive and very easy to use.
PageLayout is available for download for JDK1.5. It is distributed under LGPL.
The distribution contains the source, extensive documentation, and a large number of nontrivial examples that illustrate the simplicity and the comprehensive nature of the approach. For an introduction, look at the documentation for the class PageLayout. Some further information is contained in the documentation for the class Cell. You can also get started with a description of a typical example or with the numerous examples described in the tutorial.
If you wish, you can post a comment/question or send an email to varan78@users.sourceforge.net. We will try to respond to any questions as soon as possible.
Latest release pagelayout1.16 (05/08/2008) contains some minor bug fixes. This version may also be used with a visual layout editor Gola which minimizes the amount of hand coding you have to do to layout swing components.