1 30 31 package com.jgoodies.forms.tutorial.building; 32 33 import javax.swing.JComboBox ; 34 import javax.swing.JComponent ; 35 import javax.swing.JFrame ; 36 import javax.swing.JTextField ; 37 import javax.swing.UIManager ; 38 import javax.swing.WindowConstants ; 39 40 import com.jgoodies.forms.builder.PanelBuilder; 41 import com.jgoodies.forms.layout.CellConstraints; 42 import com.jgoodies.forms.layout.FormLayout; 43 44 64 65 public final class PanelBuilderExample { 66 67 private JTextField companyNameField; 68 private JTextField contactPersonField; 69 private JTextField orderNoField; 70 private JTextField inspectorField; 71 private JTextField referenceNoField; 72 private JComboBox approvalStatusComboBox; 73 private JTextField shipYardField; 74 private JTextField registerNoField; 75 private JTextField hullNumbersField; 76 private JComboBox projectTypeComboBox; 77 78 79 public static void main(String [] args) { 80 try { 81 UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); 82 } catch (Exception e) { 83 } 85 JFrame frame = new JFrame (); 86 frame.setTitle("Forms Tutorial :: PanelBuilder"); 87 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 88 JComponent panel = new PanelBuilderExample().buildPanel(); 89 frame.getContentPane().add(panel); 90 frame.pack(); 91 frame.show(); 92 } 93 94 95 97 100 private void initComponents() { 101 companyNameField = new JTextField (); 102 contactPersonField = new JTextField (); 103 orderNoField = new JTextField (); 104 inspectorField = new JTextField (); 105 referenceNoField = new JTextField (); 106 approvalStatusComboBox = createApprovalStatusComboBox(); 107 shipYardField = new JTextField (); 108 registerNoField = new JTextField (); 109 hullNumbersField = new JTextField (); 110 projectTypeComboBox = createProjectTypeComboBox(); 111 } 112 113 116 private JComboBox createApprovalStatusComboBox() { 117 return new JComboBox ( 118 new String [] { "In Progress", "Finished", "Released" }); 119 } 120 121 124 private JComboBox createProjectTypeComboBox() { 125 return new JComboBox ( 126 new String [] { "New Building", "Conversion", "Repair" }); 127 } 128 129 130 132 135 public JComponent buildPanel() { 136 initComponents(); 137 138 FormLayout layout = new FormLayout( 139 "right:max(40dlu;pref), 3dlu, 70dlu, 7dlu, " 140 + "right:max(40dlu;pref), 3dlu, 70dlu", 141 "p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, " + 142 "p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, " + 143 "p, 3dlu, p, 3dlu, p, 3dlu, p"); 144 145 PanelBuilder builder = new PanelBuilder(layout); 146 builder.setDefaultDialogBorder(); 147 148 CellConstraints cc = new CellConstraints(); 150 builder.addSeparator("Manufacturer", cc.xywh(1, 1, 7, 1)); 151 builder.addLabel("Company", cc.xy (1, 3)); 152 builder.add(companyNameField, cc.xywh(3, 3, 5, 1)); 153 builder.addLabel("Contact", cc.xy (1, 5)); 154 builder.add(contactPersonField, cc.xywh(3, 5, 5, 1)); 155 builder.addLabel("Order No", cc.xy (1, 7)); 156 builder.add(orderNoField, cc.xy (3, 7)); 157 158 builder.addSeparator("Inspector", cc.xywh(1, 9, 7, 1)); 159 builder.addLabel("Name", cc.xy (1, 11)); 160 builder.add(inspectorField, cc.xywh(3, 11, 5, 1)); 161 builder.addLabel("Reference No", cc.xy (1, 13)); 162 builder.add(referenceNoField, cc.xy (3, 13)); 163 builder.addLabel("Status", cc.xy (1, 15)); 164 builder.add(approvalStatusComboBox, cc.xy (3, 15)); 165 166 builder.addSeparator("Ship", cc.xywh(1, 17, 7, 1)); 167 builder.addLabel("Shipyard", cc.xy (1, 19)); 168 builder.add(shipYardField, cc.xywh(3, 19, 5, 1)); 169 builder.addLabel("Register No", cc.xy (1, 21)); 170 builder.add(registerNoField, cc.xy (3, 21)); 171 builder.addLabel("Hull No", cc.xy (5, 21)); 172 builder.add(hullNumbersField, cc.xy (7, 21)); 173 builder.addLabel("Project Type", cc.xy (1, 23)); 174 builder.add(projectTypeComboBox, cc.xy (3, 23)); 175 176 return builder.getPanel(); 177 } 178 179 } | Popular Tags |