iiley June 6th, 2007
When you want to make a form panel, i mean a table with row and columns, it’s not easy to layout them well with basic layout managers, like this example:

With the new extension class org.aswing.ext.Form(on svn now), you can easily create that form by such code:
private var form:Form;
private var frame:JFrame;
public function Form1(){
super();
AsWingManager.initAsStandard(this);
form = new Form();
form.addRow(createRightAlignLabel("ID:"), new JTextField("", 8));
form.addRow(createRightAlignLabel("NickName:"), new JTextField("", 8));
form.addRow(createRightAlignLabel("Email:"), new JTextField("", 8));
form.addRow(createRightAlignLabel("Password:"), new JTextField("", 8));
form.addRow(createRightAlignLabel("Repeat Password:"), new JTextField("", 8));
frame = new JFrame(null, "Form1");
frame.setContentPane(form);
frame.pack();
frame.show();
}
private function createRightAlignLabel(text:String):JLabel{
return new JLabel(text, null, JLabel.RIGHT);
}
Maybe you’ll say it is not hard to layout that with GridLayout or BoxLayout/SoftBoxLayout, yes, it is for that simple case, but how abou this:

It is not that easy as the first, but with Form class, it’s same easy:
private var form:Form;
private var frame:JFrame;
public function Form2(){
super();
AsWingManager.initAsStandard(this);
form = new Form();
form.setBorder(new EmptyBorder(null, new Insets(2, 2, 2, 2)));
var label:JLabel;
form.addRow(createRightAlignLabel("ID:"), new JTextField("", 8));
label = createLeftAlignLabel("Must be 4-14 letters or numbers");
//label will sit 1 and 2 columns(0 column blank)
form.addRow(null, label, label);
form.addRow(createRightAlignLabel("NickName:"), new JTextField("", 8));
form.addRow(
createRightAlignLabel("Sex:"),
form.flowLeftHold(4, new JRadioButton("Female"), new JRadioButton("Male")));
form.addRow(createRightAlignLabel("Email:"), new JTextField("", 8));
form.addRow(createRightAlignLabel("Password:"), new JTextField("", 8));
form.addRow(createRightAlignLabel("Repeat Password:"), new JTextField("", 8));
//Conform button sit at center of number 1 column(0 and 2 column blank)
form.addRow(null, form.centerHold(new JButton("Conform")), null);
frame = new JFrame(null, "Form2");
frame.setContentPane(form);
frame.pack();
frame.show();
}
private function createRightAlignLabel(text:String):JLabel{
return new JLabel(text, null, JLabel.RIGHT);
}
private function createLeftAlignLabel(text:String):JLabel{
return new JLabel(text, null, JLabel.LEFT);
}
Wow, not super hard to layout that, i did that before, well, how about this:

With Form class, it is as easy as last, just a little line code added, here:
private var form:Form;
private var frame:JFrame;
public function Form3(){
super();
AsWingManager.initAsStandard(this);
form = new Form();
form.setBorder(new EmptyBorder(null, new Insets(2, 2, 2, 2)));
var label:JLabel;
form.addRow(createRightAlignLabel("ID:"), new JTextField("", 8), createLeftAlignLabel("Case sensitive"));
label = createLeftAlignLabel("Must be 4-14 letters or numbers");
//label will sit 1 and 2 columns(0 column blank)
form.addRow(null, label, label);
form.addRow(createRightAlignLabel("NickName:"), new JTextField("", 8), createLeftAlignLabel("Case sensitive"));
form.addRow(
createRightAlignLabel("Sex:"),
form.flowLeftHold(4, new JRadioButton("Female"), new JRadioButton("Male")), new JRadioButton("Both?"));
//add a separator
form.addSeparator();
form.addRow(createRightAlignLabel("Email:"), new JTextField("", 8));
form.addRow(createRightAlignLabel("Password:"), new JTextField("", 8));
form.addRow(createRightAlignLabel("Repeat Password:"), new JTextField("", 8));
//add a separator
form.addSeparator();
//use append to make it sit the whole row
form.append(form.flowLeftHold(2, new JCheckBox("I Accept"), new JLabelButton(" The licence")));
//Conform button sit at center of number 1 column(0 and 2 column blank)
form.addRow(null, form.centerHold(new JButton("Conform")), null);
frame = new JFrame(null, "Form3");
frame.setContentPane(form);
frame.pack();
frame.show();
}
private function createRightAlignLabel(text:String):JLabel{
return new JLabel(text, null, JLabel.RIGHT);
}
private function createLeftAlignLabel(text:String):JLabel{
return new JLabel(text, null, JLabel.LEFT);
}
Is that make you easier layout such style tables for you? Hope so.
Download the example source.