1 package org.mlc.swing.example; 2 3 import java.awt.*; 4 import javax.swing.*; 5 import org.mlc.swing.layout.LayoutFrame; 6 7 /*** 8 * @author Michael Connor 9 */ 10 public class CustomerPanel extends javax.swing.JPanel 11 { 12 javax.swing.JComboBox suffixCombo = new javax.swing.JComboBox(); 13 14 javax.swing.JLabel lastNameLabel = new javax.swing.JLabel("Last Name"); 15 16 javax.swing.JTextField firstNameText = new javax.swing.JTextField(); 17 18 javax.swing.JTextField lastNameText = new javax.swing.JTextField(); 19 20 javax.swing.JTextField faxText = new javax.swing.JTextField(); 21 22 java.awt.Component contactSeparator = com.jgoodies.forms.factories.DefaultComponentFactory 23 .getInstance().createSeparator("Contact Info"); 24 25 javax.swing.JLabel surnameLabel = new javax.swing.JLabel("Surname"); 26 27 javax.swing.JButton okButton = new javax.swing.JButton("OK"); 28 29 javax.swing.JButton cancelButton = new javax.swing.JButton("Cancel"); 30 31 java.awt.Component buttonBar = com.jgoodies.forms.factories.ButtonBarFactory 32 .buildRightAlignedBar(new JButton[] { okButton, cancelButton }); 33 34 javax.swing.JLabel workPhoneLabel = new javax.swing.JLabel("Work Phone"); 35 36 javax.swing.JTextField workPhoneText = new javax.swing.JTextField(); 37 38 javax.swing.JTextField emailText = new javax.swing.JTextField(); 39 40 javax.swing.JTextField homePhoneText = new javax.swing.JTextField(); 41 42 javax.swing.JLabel faxLabel = new javax.swing.JLabel("Fax Number"); 43 44 java.awt.Component ordersSeparator = com.jgoodies.forms.factories.DefaultComponentFactory 45 .getInstance().createSeparator("Orders"); 46 47 javax.swing.JComboBox surnameCombo = new javax.swing.JComboBox(); 48 49 java.awt.Component nameSeparator = com.jgoodies.forms.factories.DefaultComponentFactory 50 .getInstance().createSeparator("Name"); 51 52 javax.swing.JLabel suffixLabel = new javax.swing.JLabel("Suffix"); 53 54 javax.swing.JLabel emailLabel = new javax.swing.JLabel("E-mail"); 55 56 javax.swing.JLabel homePhoneLabel = new javax.swing.JLabel("Home Phone"); 57 58 javax.swing.JLabel firstNameLabel = new javax.swing.JLabel("First Name"); 59 60 javax.swing.JTable orderTableControl = new javax.swing.JTable(); 61 62 javax.swing.JScrollPane orderTable = new javax.swing.JScrollPane( 63 orderTableControl); 64 65 public CustomerPanel() 66 { 67 super(); 68 java.io.InputStream is = CustomerPanel.class.getResourceAsStream("customerLayout.xml"); 69 if (is == null) 70 { 71 System.err.println("Could not find constraints customerLayout.xml"); 72 return; 73 } 74 org.mlc.swing.layout.LayoutConstraintsManager layoutConstraintsManager = 75 org.mlc.swing.layout.LayoutConstraintsManager.getLayoutConstraintsManager(is); 76 setBorder(com.jgoodies.forms.factories.Borders.DIALOG_BORDER); 77 LayoutManager layout = layoutConstraintsManager.createLayout("panel", this); 78 this.setLayout(layout); 79 80 this.add(nameSeparator, "nameSeparator"); 81 this.add(surnameLabel, "surnameLabel"); 82 this.add(surnameCombo, "surnameCombo"); 83 this.add(firstNameLabel, "firstNameLabel"); 84 this.add(firstNameText, "firstNameText"); 85 this.add(lastNameLabel, "lastNameLabel"); 86 this.add(lastNameText, "lastNameText"); 87 this.add(suffixLabel, "suffixLabel"); 88 this.add(suffixCombo, "suffixCombo"); 89 this.add(contactSeparator, "contactSeparator"); 90 this.add(workPhoneLabel, "workPhoneLabel"); 91 this.add(workPhoneText, "workPhoneText"); 92 this.add(homePhoneLabel, "homePhoneLabel"); 93 this.add(homePhoneText, "homePhoneText"); 94 this.add(faxLabel, "faxLabel"); 95 this.add(faxText, "faxText"); 96 this.add(emailLabel, "emailLabel"); 97 this.add(emailText, "emailText"); 98 this.add(ordersSeparator, "ordersSeparator"); 99 this.add(orderTable, "orderTable"); 100 this.add(buttonBar, "buttonBar"); 101 102 LayoutFrame frame = new LayoutFrame(layoutConstraintsManager); 103 frame.setVisible(true); 104 } 105 106 public static void main(String[] args) 107 { 108 UIDefaults defaults = UIManager.getDefaults(); 109 defaults.put("Label.font", new javax.swing.plaf.FontUIResource( 110 new java.awt.Font("Arial", java.awt.Font.PLAIN, 12))); 111 defaults.put("ComboBox.background", new javax.swing.plaf.ColorUIResource( 112 255, 255, 255)); 113 114 CustomerPanel customerPanel = new CustomerPanel(); 115 116 JFrame frame = new JFrame("Edit Customer"); 117 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 118 frame.getContentPane().setLayout(new BorderLayout()); 119 frame.getContentPane().add(customerPanel, BorderLayout.CENTER); 120 frame.setSize(600, 700); 121 frame.setVisible(true); 122 } 123 124 }