1 30 31 package com.jgoodies.forms.tutorial.building; 32 33 import javax.swing.*; 34 35 import com.jgoodies.forms.builder.PanelBuilder; 36 import com.jgoodies.forms.layout.FormLayout; 37 38 53 54 public final class DynamicRowsExample { 55 56 private JTextField identifierField; 57 private JTextField ptiField; 58 private JTextField powerField; 59 private JTextField lenField; 60 private JTextField daField; 61 private JTextField diField; 62 private JTextField da2Field; 63 private JTextField di2Field; 64 private JTextField rField; 65 private JTextField dField; 66 private JComboBox locationCombo; 67 private JTextField kFactorField; 68 private JCheckBox holesCheckBox; 69 private JCheckBox slotsCheckBox; 70 71 72 public static void main(String [] args) { 73 try { 74 UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); 75 } catch (Exception e) { 76 } 78 JFrame frame = new JFrame(); 79 frame.setTitle("Forms Tutorial :: Dynamic Rows"); 80 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 81 JComponent panel = new DynamicRowsExample().buildPanel(); 82 frame.getContentPane().add(panel); 83 frame.pack(); 84 frame.show(); 85 } 86 87 88 90 93 private void initComponents() { 94 identifierField = new JTextField(); 95 ptiField = new JTextField(); 96 powerField = new JTextField(); 97 lenField = new JTextField(); 98 daField = new JTextField(); 99 diField = new JTextField(); 100 da2Field = new JTextField(); 101 di2Field = new JTextField(); 102 rField = new JTextField(); 103 dField = new JTextField(); 104 locationCombo = createLocationComboBox(); 105 kFactorField = new JTextField(); 106 holesCheckBox = new JCheckBox("Has radial holes", true); 107 slotsCheckBox = new JCheckBox("Has longitudinal slots"); 108 } 109 110 113 private JComboBox createLocationComboBox() { 114 return new JComboBox( 115 new String [] { 116 "Propeller nut thread", 117 "Stern tube front area", 118 "Shaft taper" }); 119 } 120 121 122 124 127 public JComponent buildPanel() { 128 initComponents(); 129 130 FormLayout layout = new FormLayout( 131 "right:max(40dlu;pref), 3dlu, 70dlu, 7dlu, " 132 + "right:max(40dlu;pref), 3dlu, 70dlu", 133 "p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, " 134 + "p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, " 135 + "p, 3dlu, p, 3dlu, p, 3dlu, p"); 136 137 PanelBuilder builder = new PanelBuilder(layout); 138 builder.setDefaultDialogBorder(); 139 140 builder.addSeparator("Segment"); 141 builder.nextLine(2); 142 143 builder.addLabel("Identifier"); builder.nextColumn(2); 144 builder.add(identifierField); 145 builder.nextLine(2); 146 147 builder.addLabel("PTI [kW]"); builder.nextColumn(2); 148 builder.add(ptiField); builder.nextColumn(2); 149 builder.addLabel("Power [kW]"); builder.nextColumn(2); 150 builder.add(powerField); 151 builder.nextLine(2); 152 153 builder.addLabel("len [mm]"); builder.nextColumn(2); 154 builder.add(lenField); 155 builder.nextLine(2); 156 157 builder.addSeparator("Diameters"); 158 builder.nextLine(2); 159 160 builder.addLabel("da [mm]"); builder.nextColumn(2); 161 builder.add(daField); builder.nextColumn(2); 162 builder.addLabel("di [mm]"); builder.nextColumn(2); 163 builder.add(diField); 164 builder.nextLine(2); 165 166 builder.addLabel("da2 [mm]"); builder.nextColumn(2); 167 builder.add(da2Field); builder.nextColumn(2); 168 builder.addLabel("di2 [mm]"); builder.nextColumn(2); 169 builder.add(di2Field); 170 171 builder.nextLine(2); 172 builder.addLabel("R [mm]"); builder.nextColumn(2); 173 builder.add(rField); builder.nextColumn(2); 174 builder.addLabel("D [mm]"); builder.nextColumn(2); 175 builder.add(dField); 176 builder.nextLine(2); 177 178 builder.addSeparator("Criteria"); 179 builder.nextLine(2); 180 181 builder.addLabel("Location"); builder.nextColumn(2); 182 builder.add(locationCombo); builder.nextColumn(2); 183 builder.addLabel("k-factor"); builder.nextColumn(2); 184 builder.add(kFactorField); 185 builder.nextLine(2); 186 187 builder.addLabel("Holes"); builder.nextColumn(2); 188 builder.setColumnSpan(5); 189 builder.add(holesCheckBox); 190 builder.setColumnSpan(1); 191 builder.nextLine(2); 192 193 builder.addLabel("Slots"); builder.nextColumn(2); 194 builder.setColumnSpan(5); 195 builder.add(slotsCheckBox); 196 builder.setColumnSpan(1); 197 198 return builder.getPanel(); 199 } 200 201 202 } | Popular Tags |