Baggie Layout is a Swing LayoutManager (created in May 2006). It replaces GridBagLayout by offering all the same functionality (except for x,y coordinate positioning). It allows you to lay out your container in two ways, XML (preferred), or constraint objects.
The preferred way is to write xml, with an "id" attribute on each "td" element to place components. The syntax is almost the same as strict xhtml. Some attribute names are different, such as align which is divided into horizontal and vertical. Compatibility is maintained for user friendliness, so "align" is assumed to be horizontal align, or you can specify both horizontal and vertical in the same attribute separated by a space or comma.
The second way to lay out your container is to use the BaggieConstraint bean. It is alot like the GridBagConstraints object, having similar properties, but it follows the JavaBean design pattern, and uses enums instead of primitive int fields. Instead of fields to set how the constraint works, you call setter methods. You can also call a single method that parses all your properties from one string if that is more convenient.
It will always remain free and open source.
BaggieLayout on SourceForge
Download
JavaDoc API
Change Log
LGPL License
Since a good LayoutManager is something should already be included in the JRE but is not, I hope to one day make BaggieLayout part of the standard JRE. I always wanted a LayoutManager like this, but never knew how to make one, or never tried until recently. If you can help me do this, please email me.
BaggieLayout.setPrintingWarnings(true); BaggieLayout.setPrintingWarningTraces(true);
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame f = new SizeControlledJFrame("Example");It uses some unorthodox methods to control the window size, and so far was only tested thorougly on WindowsXP.
BaggieLayout layout = new BaggieLayout( this, //this is the JPanel "<table width='1,2' height='1,1,0'>" + " <tr alignAll='left'>" + " <td colSpan='2' id='menuBar' />" + " </tr>" + " <tr fillAll='both' borderAll='EtchedBorder'>" + " <td id='fileTree' />" + " <td id='editor' />" + " </tr>" + " <tr>" + " <td align='left' margin='0 5 0 5' fill='horizontal' colSpan='2' id='statusBar' />" + " </tr>" + "</table>" );
this.add( menuBar, "menuBar" ); this.add( treeScroll, "fileTree" ); this.add( editorScroll, "editor" ); this.add( statusBar, "statusBar" );
BaggieLayout layout = new BaggieLayout( this, "1,1", "1 1 1" );
BaggieConstraint cst = new BaggieConstraint(); cst.setAlign( BaggieConstraint.Align.LEFT ); cst.setColSpan(2); this.add( menuBar, cst.endRow() ); cst.setColSpan(1); cst.setFill( BaggieConstraint.Fill.BOTH ); this.add( treeScroll, cst ); this.add( editorScroll, cst.endRow() ); cst.setMargin(0,5,0,5); cst.setColSpan(2); cst.setFill(BaggieConstraint.Fill.HORIZONTAL); this.add( statusBar, cst.endRow() );
Java 6.0
Original author and only coder: Peter Maloney <circumlocuter@yahoo.com> Additional contributiors: (Ideas, misc. help) Stephen Maloney Sam Maloney <sam.maloney@gmail.com> Testing and bug reports: Stephen Maloney Sam Maloney <sam.maloney@gmail.com>