A Layout manager that can be used to layout 2 columns of components. The alignment and fill type of the columns can be set by using the FormConstraint class.
A couple of predefined FormConstraint objects have been defined:
import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.Box; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.border.EmptyBorder; import javax.swing.border.EtchedBorder; import org.bounce.FormLayout; import org.bounce.FormConstraints; public class FormLayoutTest { public static void main( String[] args) { try { JPanel panel = new JPanel( new FormLayout( 10, 5)); panel.setBorder( new EmptyBorder( 10, 10, 10, 10)); panel.add( new JLabel( "FormLayout using predefined FormConstraints:"), FormLayout.FULL); panel.add( new JLabel( "LEFT"), FormLayout.LEFT); panel.add( new JTextField( "RIGHT"), FormLayout.RIGHT); panel.add( new JLabel( "LEFT"), FormLayout.LEFT); panel.add( new JTextField( "RIGHT_FILL"), FormLayout.RIGHT_FILL); panel.add( new JTextField( "FULL"), FormLayout.FULL); panel.add( new JTextField( "FULL_FILL"), FormLayout.FULL_FILL); panel.add( Box.createVerticalStrut( 20), FormLayout.FULL); panel.add( new JLabel( "FormLayout using custom FormConstraints:"), FormLayout.FULL); JTextPane text = new JTextPane(); text.setText( "LEFT"); text.setPreferredSize( new Dimension( 100, 50)); text.setBorder( new EtchedBorder()); panel.add( text, FormLayout.LEFT); panel.add( new JTextField( "RIGHT, CENTER, BOTTOM"), new FormConstraints( FormConstraints.RIGHT, FormConstraints.CENTER, FormConstraints.BOTTOM)); panel.add( new JLabel( "LEFT, RIGHT"), new FormConstraints( FormConstraints.LEFT, FormConstraints.RIGHT)); panel.add( new JTextField( "RIGHT, RIGHT"), new FormConstraints( FormConstraints.RIGHT, FormConstraints.RIGHT)); JFrame f = new JFrame( "FormLayoutTest"); f.getContentPane().setLayout( new BorderLayout()); f.getContentPane().add( panel, BorderLayout.CENTER); f.setSize( new Dimension( 400, 300)); f.setVisible( true); } catch ( Throwable e) { e.printStackTrace(); System.exit( 1); } } }