1   package org.springframework.richclient.form;
2   
3   import javax.swing.JCheckBox;
4   import javax.swing.JComboBox;
5   import javax.swing.JFrame;
6   import javax.swing.JLabel;
7   import javax.swing.JPanel;
8   import javax.swing.JTextField;
9   
10  import org.springframework.richclient.layout.TableLayoutBuilder;
11  
12  /**
13   * Simple Panel that mimics a panel created by a visual designer.
14   * @author Peter De Bruycker
15   */
16  public class SimplePanel extends JPanel {
17      private JTextField stringField;
18      private JComboBox comboBox;
19      private JCheckBox checkBox;
20      private JTextField nestedField;
21  
22      public SimplePanel() {
23          TableLayoutBuilder builder = new TableLayoutBuilder(this);
24  
25          stringField = new JTextField(10);
26          stringField.setName("stringProperty");
27  
28          comboBox = new JComboBox(new String[] { "item 0", "item 1", "item 2" });
29          comboBox.setName("comboProperty");
30  
31          checkBox = new JCheckBox("checkbox");
32          checkBox.setName("booleanProperty");
33  
34          builder.cell(new JLabel("string"));
35          builder.gapCol();
36          builder.cell(stringField);
37          builder.relatedGapRow();
38          builder.cell(new JLabel("combo"));
39          builder.gapCol();
40          builder.cell(comboBox);
41          builder.relatedGapRow();
42          builder.cell(checkBox);
43          builder.relatedGapRow();
44          
45          JPanel nestedPanel =new JPanel();
46          nestedField = new JTextField("test");
47          nestedField.setName("nestedField");
48          nestedPanel.add(nestedField);
49          
50          builder.cell(nestedPanel);
51  
52          builder.getPanel();
53      }
54  
55      public static void main(String[] args) {
56          JFrame frame = new JFrame("test");
57          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
58  
59          frame.add(new SimplePanel());
60  
61          frame.pack();
62          frame.setLocationRelativeTo(null);
63          frame.setVisible(true);
64      }
65  
66      public JTextField getStringField() {
67          return stringField;
68      }
69  
70      public JComboBox getComboBox() {
71          return comboBox;
72      }
73  
74      public JCheckBox getCheckBox() {
75          return checkBox;
76      }
77      
78      public JTextField getNestedField() {
79          return nestedField;
80      }
81  }