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.factories.Borders; 38 import com.jgoodies.forms.factories.DefaultComponentFactory; 39 import com.jgoodies.forms.layout.CellConstraints; 40 import com.jgoodies.forms.layout.FormLayout; 41 42 60 61 public final class PlainExample { 62 63 private JTextField companyNameField; 64 private JTextField contactPersonField; 65 private JTextField orderNoField; 66 private JTextField inspectorField; 67 private JTextField referenceNoField; 68 private JComboBox approvalStatusComboBox; 69 private JTextField shipYardField; 70 private JTextField registerNoField; 71 private JTextField hullNumbersField; 72 private JComboBox projectTypeComboBox; 73 74 75 public static void main(String [] args) { 76 try { 77 UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); 78 } catch (Exception e) { 79 } 81 JFrame frame = new JFrame(); 82 frame.setTitle("Forms Tutorial :: Plain Building"); 83 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 84 JComponent panel = new PlainExample().buildPanel(); 85 frame.getContentPane().add(panel); 86 frame.pack(); 87 frame.show(); 88 } 89 90 91 93 96 private void initComponents() { 97 companyNameField = new JTextField(); 98 contactPersonField = new JTextField(); 99 orderNoField = new JTextField(); 100 inspectorField = new JTextField(); 101 referenceNoField = new JTextField(); 102 approvalStatusComboBox = createApprovalStatusComboBox(); 103 shipYardField = new JTextField(); 104 registerNoField = new JTextField(); 105 hullNumbersField = new JTextField(); 106 projectTypeComboBox = createProjectTypeComboBox(); 107 } 108 109 112 private JComboBox createApprovalStatusComboBox() { 113 return new JComboBox( 114 new String [] { "In Progress", "Finished", "Released" }); 115 } 116 117 120 private JComboBox createProjectTypeComboBox() { 121 return new JComboBox( 122 new String [] { "New Building", "Conversion", "Repair" }); 123 } 124 125 126 128 131 public JComponent buildPanel() { 132 initComponents(); 133 134 FormLayout layout = new FormLayout( 135 "right:max(40dlu;pref), 3dlu, 70dlu, 7dlu, " 136 + "right:max(40dlu;pref), 3dlu, 70dlu", 137 "p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, " + 138 "p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, " + 139 "p, 3dlu, p, 3dlu, p, 3dlu, p"); 140 141 JPanel panel = new JPanel(layout); 142 panel.setBorder(Borders.DIALOG_BORDER); 143 144 CellConstraints cc = new CellConstraints(); 146 panel.add(createSeparator("Manufacturer"), cc.xywh(1, 1, 7, 1)); 147 panel.add(new JLabel("Company"), cc.xy (1, 3)); 148 panel.add(companyNameField, cc.xywh(3, 3, 5, 1)); 149 panel.add(new JLabel("Contact"), cc.xy (1, 5)); 150 panel.add(contactPersonField, cc.xywh(3, 5, 5, 1)); 151 panel.add(new JLabel("Order No"), cc.xy (1, 7)); 152 panel.add(orderNoField, cc.xy (3, 7)); 153 154 panel.add(createSeparator("Inspector"), cc.xywh(1, 9, 7, 1)); 155 panel.add(new JLabel("Name"), cc.xy (1, 11)); 156 panel.add(inspectorField, cc.xywh(3, 11, 5, 1)); 157 panel.add(new JLabel("Reference No"), cc.xy (1, 13)); 158 panel.add(referenceNoField, cc.xy (3, 13)); 159 panel.add(new JLabel("Status"), cc.xy (1, 15)); 160 panel.add(approvalStatusComboBox, cc.xy (3, 15)); 161 162 panel.add(createSeparator("Ship"), cc.xywh(1, 17, 7, 1)); 163 panel.add(new JLabel("Shipyard"), cc.xy (1, 19)); 164 panel.add(shipYardField, cc.xywh(3, 19, 5, 1)); 165 panel.add(new JLabel("Register No"), cc.xy (1, 21)); 166 panel.add(registerNoField, cc.xy (3, 21)); 167 panel.add(new JLabel("Hull No"), cc.xy (5, 21)); 168 panel.add(hullNumbersField, cc.xy (7, 21)); 169 panel.add(new JLabel("Project Type"), cc.xy (1, 23)); 170 panel.add(projectTypeComboBox, cc.xy (3, 23)); 171 172 return panel; 173 } 174 175 181 private Component createSeparator(String text) { 182 return DefaultComponentFactory.getInstance().createSeparator(text); 183 } 184 185 } | Popular Tags |