1 30 31 package com.jgoodies.forms.tutorial; 32 33 import javax.swing.JComponent ; 34 import javax.swing.JFrame ; 35 import javax.swing.JTextField ; 36 import javax.swing.UIManager ; 37 import javax.swing.WindowConstants ; 38 39 import com.jgoodies.forms.builder.PanelBuilder; 40 import com.jgoodies.forms.layout.CellConstraints; 41 import com.jgoodies.forms.layout.FormLayout; 42 43 54 55 public final class QuickStartExample { 56 57 private JTextField companyField; 58 private JTextField contactField; 59 private JTextField ptiField; 60 private JTextField powerField; 61 private JTextField radiusField; 62 private JTextField diameterField; 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 :: Quick Start"); 73 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 74 JComponent panel = new QuickStartExample().buildPanel(); 75 frame.getContentPane().add(panel); 76 frame.pack(); 77 frame.show(); 78 } 79 80 81 83 87 private void initComponents() { 88 companyField = new JTextField (); 89 contactField = new JTextField (); 90 ptiField = new JTextField (6); 91 powerField = new JTextField (10); 92 radiusField = new JTextField (8); 93 diameterField = new JTextField (8); 94 } 95 96 98 103 public JComponent buildPanel() { 104 initComponents(); 107 108 FormLayout layout = new FormLayout( 112 "right:pref, 3dlu, pref, 7dlu, right:pref, 3dlu, pref", "p, 3dlu, p, 3dlu, p, 9dlu, p, 3dlu, p, 3dlu, p"); 115 layout.setColumnGroups(new int[][]{{1, 5}, {3, 7}}); 117 118 PanelBuilder builder = new PanelBuilder(layout); 121 builder.setDefaultDialogBorder(); 122 123 CellConstraints cc = new CellConstraints(); 125 126 129 builder.addSeparator("General", cc.xywh(1, 1, 7, 1)); 131 builder.addLabel("Company", cc.xy (1, 3)); 132 builder.add(companyField, cc.xywh(3, 3, 5, 1)); 133 builder.addLabel("Contact", cc.xy (1, 5)); 134 builder.add(contactField, cc.xywh(3, 5, 5, 1)); 135 136 builder.addSeparator("Propeller", cc.xywh(1, 7, 7, 1)); 137 builder.addLabel("PTI [kW]", cc.xy (1, 9)); 138 builder.add(ptiField, cc.xy (3, 9)); 139 builder.addLabel("Power [kW]", cc.xy (5, 9)); 140 builder.add(powerField, cc.xy (7, 9)); 141 builder.addLabel("R [mm]", cc.xy (1, 11)); 142 builder.add(radiusField, cc.xy (3, 11)); 143 builder.addLabel("D [mm]", cc.xy (5, 11)); 144 builder.add(diameterField, cc.xy (7, 11)); 145 146 return builder.getPanel(); 148 } 149 150 } | Popular Tags |