1 30 31 package com.jgoodies.forms.tutorial.building; 32 33 import javax.swing.*; 34 35 import com.jgoodies.forms.extras.DefaultFormBuilder; 36 import com.jgoodies.forms.layout.CellConstraints; 37 import com.jgoodies.forms.layout.FormLayout; 38 import com.jgoodies.forms.layout.RowSpec; 39 40 54 55 public final class DefaultFormWithCustomRowsExample { 56 57 private JTextField name1Field; 58 private JTextArea comment1Area; 59 private JTextField name2Field; 60 private JTextArea comment2Area; 61 private JTextField name3Field; 62 private JTextArea comment3Area; 63 64 65 public static void main(String [] args) { 66 try { 67 UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); 68 } catch (Exception e) { 69 } 71 JFrame frame = new JFrame(); 72 frame.setTitle("Forms Tutorial :: Custom Rows"); 73 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 74 JComponent panel = new DefaultFormWithCustomRowsExample().buildPanel(); 75 frame.getContentPane().add(panel); 76 frame.pack(); 77 frame.show(); 78 } 79 80 81 83 86 private void initComponents() { 87 name1Field = new JTextField("Name (font baselines shall be aligned)"); 88 comment1Area = new JTextArea(2, 20); 89 comment1Area.setText("The label is a little bit too high.\nLikely the font baselines are unaligned."); 90 name2Field = new JTextField("Name (font baselines shall be aligned)"); 91 comment2Area = new JTextArea(2, 20); 92 comment2Area.setText("The label is positioned well.\nThe font baselines shall be aligned."); 93 name3Field = new JTextField("Name (font baselines shall be aligned)"); 94 comment3Area = new JTextArea(2, 20); 95 comment3Area.setText("The label is positioned well.\nThe font baselines shall be aligned."); 96 } 97 98 99 101 105 public JComponent buildPanel() { 106 initComponents(); 107 108 FormLayout layout = new FormLayout( 109 "right:pref, 3dlu, min:grow", 110 ""); 111 DefaultFormBuilder builder = new DefaultFormBuilder(layout); 112 builder.setDefaultDialogBorder(); 113 builder.setRowGroupingEnabled(true); 114 115 CellConstraints cc = new CellConstraints(); 116 117 builder.appendSeparator("Single Custom Row"); 123 builder.append("Name", name1Field); 124 builder.appendRow(builder.getLineGapSpec()); 125 builder.appendRow(new RowSpec("top:31dlu")); builder.nextLine(2); 127 builder.append("Comment"); 128 builder.add(new JScrollPane(comment1Area), 129 cc.xy(builder.getColumn(), builder.getRow(), "fill, fill")); 130 builder.nextLine(); 131 132 builder.appendSeparator("Standard + Custom Row"); 138 builder.append("Name", name2Field); 139 builder.append("Comment"); 140 builder.appendRow(new RowSpec("17dlu")); builder.add(new JScrollPane(comment2Area), 142 cc.xywh(builder.getColumn(), builder.getRow(), 1, 2)); 143 builder.nextLine(2); 144 145 builder.appendSeparator("Two Standard Rows"); 151 builder.append("Name", name3Field); 152 builder.append("Comment"); 153 builder.nextLine(); 154 builder.append(""); 155 builder.nextRow(-2); 156 builder.add(new JScrollPane(comment3Area), 157 cc.xywh(builder.getColumn(), builder.getRow(), 1, 3)); 158 159 return builder.getPanel(); 160 } 161 162 163 } | Popular Tags |