1 30 31 package com.jgoodies.forms.tutorial.building; 32 33 import java.awt.Component ; 34 35 import javax.swing.*; 36 37 import com.jgoodies.forms.builder.PanelBuilder; 38 import com.jgoodies.forms.layout.CellConstraints; 39 import com.jgoodies.forms.layout.FormLayout; 40 41 58 59 public final class RowCounterExample { 60 61 private JTextField identifierField; 62 private JTextField powerField; 63 private JTextField speedField; 64 private JComboBox materialComboBox; 65 private JComboBox iceClassComboBox; 66 private JTextArea machineryCommentArea; 67 private JTextArea inspectionCommentArea; 68 69 70 public static void main(String [] args) { 71 try { 72 UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); 73 } catch (Exception e) { 74 } 76 JFrame frame = new JFrame(); 77 frame.setTitle("Forms Tutorial :: Row Counter"); 78 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 79 JComponent panel = new RowCounterExample().buildPanel(); 80 frame.getContentPane().add(panel); 81 frame.pack(); 82 frame.show(); 83 } 84 85 86 88 91 private void initComponents() { 92 identifierField = new JTextField(); 93 powerField = new JTextField(); 94 speedField = new JTextField(); 95 materialComboBox = createMaterialComboBox(); 96 iceClassComboBox = createIceClassComboBox(); 97 machineryCommentArea = new JTextArea(); 98 inspectionCommentArea = new JTextArea(); 99 } 100 101 104 private JComboBox createMaterialComboBox() { 105 return new JComboBox(new String [] {"C45E, ReH=600", 106 "Bolt Material, ReH=800"}); 107 } 108 111 private JComboBox createIceClassComboBox() { 112 return new JComboBox(new String [] { "E", "E1", "E2", "E3", "E4" }); 113 } 114 115 116 118 121 public JComponent buildPanel() { 122 initComponents(); 123 Component machineryPane = new JScrollPane(machineryCommentArea); 124 Component inspectionPane = new JScrollPane(inspectionCommentArea); 125 126 FormLayout layout = new FormLayout( 127 "right:max(40dlu;pref), 3dlu, 70dlu, 7dlu, " 128 + "right:max(40dlu;pref), 3dlu, 70dlu", 129 "p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, " 130 + "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p"); 131 layout.setRowGroups(new int[][] { { 3, 13, 15, 17 } }); 132 133 PanelBuilder builder = new PanelBuilder(layout); 134 builder.setDefaultDialogBorder(); 135 136 CellConstraints cc = new CellConstraints(); 137 int row = 1; 138 139 builder.addSeparator("Shaft", cc.xywh(1, row++, 7, 1)); 140 row++; 141 142 builder.addLabel("Identifier", cc.xy (1, row)); 143 builder.add(identifierField, cc.xy (3, row++)); 144 row++; 145 146 builder.addLabel("Power", cc.xy (1, row)); 147 builder.add(powerField, cc.xy (3, row)); 148 builder.addLabel("Speed", cc.xy (5, row)); 149 builder.add(speedField, cc.xy (7, row++)); 150 row++; 151 152 builder.addLabel("Material", cc.xy (1, row)); 153 builder.add(materialComboBox, cc.xy (3, row)); 154 builder.addLabel("Ice Class", cc.xy (5, row)); 155 builder.add(iceClassComboBox, cc.xy (7, row++)); 156 row++; 157 158 builder.addSeparator("Comments", cc.xywh(1, row++, 7, 1)); 159 row++; 160 161 builder.addLabel("Machinery", cc.xy (1, row)); 162 builder.add(machineryPane, cc.xywh(3, row++, 5, 3, "f, f")); 163 row += 3; 164 165 builder.addLabel("Inspection", cc.xy (1, row)); 166 builder.add(inspectionPane, cc.xywh(3, row++, 5, 3, "f, f")); 167 168 return builder.getPanel(); 169 } 170 171 172 } | Popular Tags |