major colum + "right:max(40dlu;pref), 3dlu, 80dlu", // 2nd major column ""); // add rows dynamically DefaultFormBuilder builder = new DefaultFormBuilder(layout); builder.setDefaultDialogBorder(); builder.appendSeparator("Flange"); builder.append("Identifier", identifierField); builder.nextLine(); builder.append("PTI [kW]", new JTextField()); builder.append("Power [kW]", new JTextField()); builder.append("s [mm]", new JTextField()); builder.nextLine(); builder.appendSeparator("Diameters"); builder.append("da [mm]", new JTextField()); builder.append("di [mm]", new JTextField()); builder.append("da2 [mm]", new JTextField()); builder.append("di2 [mm]", new JTextField()); builder.append("R [mm]", new JTextField()); builder.append("D [mm]", new JTextField()); builder.appendSeparator("Criteria"); builder.append("Location", buildLocationComboBox()); builder.append("k-factor", new JTextField()); builder.appendSeparator("Bolts"); builder.append("Material", ViewerUIFactory.buildMaterialComboBox()); builder.nextLine(); builder.append("Numbers", new JTextField()); builder.nextLine(); builder.append("ds [mm]", new JTextField()); }
Custom Row Example:
public JComponent buildPanel() { initComponents(); FormLayout layout = new FormLayout( "right:pref, 3dlu, default:grow", ""); DefaultFormBuilder builder = new DefaultFormBuilder(layout); builder.setDefaultDialogBorder(); builder.setRowGroupingEnabled(true); CellConstraints cc = new CellConstraints(); // In this approach, we add a gap and a custom row. // The advantage of this approach is, that we can express // the row spec and comment area cell constraints freely. // The disadvantage is the misalignment of the leading label. // Also the row's height may be inconsistent with other rows. builder.appendSeparator("Single Custom Row"); builder.append("Name", name1Field); builder.appendRow(builder.getLineGapSpec()); builder.appendRow(new RowSpec("top:31dlu")); // Assumes line is 14, gap is 3 builder.nextLine(2); builder.append("Comment"); builder.add(new JScrollPane(comment1Area), cc.xy(builder.getColumn(), builder.getRow(), "fill, fill")); builder.nextLine(); // In this approach, we append a standard row with gap before it. // The advantage is, that the leading label is aligned well. // The disadvantage is that the comment area now spans // multiple cells and is slightly less flexible. // Also the row's height may be inconsistent with other rows. builder.appendSeparator("Standard + Custom Row"); builder.append("Name", name2Field); builder.append("Comment"); builder.appendRow(new RowSpec("17dlu")); // Assumes line is 14, gap is 3 builder.add(new JScrollPane(comment2Area), cc.xywh(builder.getColumn(), builder.getRow(), 1, 2)); builder.nextLine(2); // In this approach, we append two standard rows with associated gaps. // The advantage is, that the leading label is aligned well, // and the height is consistent with other rows. // The disadvantage is that the comment area now spans // multiple cells and is slightly less flexible. builder.appendSeparator("Two Standard Rows"); builder.append("Name", name3Field); builder.append("Comment"); builder.nextLine(); builder.append(""); builder.nextRow(-2); builder.add(new JScrollPane(comment3Area), cc.xywh(builder.getColumn(), builder.getRow(), 1, 3)); return builder.getPanel(); }
TODO: Consider adding a method for appending a component that spans the remaining columns in the current row. Method name candidates are #appendFullSpan
and #appendRemaining
.
@author Karsten Lentzsch
@version $Revision: 1.10 $
@since 1.0.3
@see com.jgoodies.forms.builder.AbstractFormBuilder
@see com.jgoodies.forms.factories.FormFactory
@see com.jgoodies.forms.layout.FormLayout