1 30 31 package com.jgoodies.forms.tutorial.building; 32 33 import javax.swing.*; 34 35 import com.jgoodies.forms.extras.DefaultFormBuilder; 36 import com.jgoodies.forms.layout.CellConstraints; 37 import com.jgoodies.forms.layout.FormLayout; 38 import com.jgoodies.forms.layout.RowSpec; 39 40 52 53 public final class DefaultFormWithCustomAreasExample { 54 55 56 57 public static void main(String [] args) { 58 try { 59 UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); 60 } catch (Exception e) { 61 } 63 JFrame frame = new JFrame(); 64 frame.setTitle("Forms Tutorial :: Custom Areas"); 65 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 66 JComponent panel = new DefaultFormWithCustomAreasExample().buildPanel(); 67 frame.getContentPane().add(panel); 68 frame.pack(); 69 frame.show(); 70 } 71 72 73 74 76 public JComponent buildPanel() { 77 JTabbedPane tabbedPane = new JTabbedPane(); 78 tabbedPane.putClientProperty("jgoodies.noContentBorder", Boolean.TRUE); 79 80 tabbedPane.add(buildCustomAreaWithAlignedLabelPanel(), "Aligned label"); 81 tabbedPane.add(buildCustomAreaWithTopLabelPanel(), "Top label"); 82 tabbedPane.add(buildCustomAreaWithSeparatorPanel(), "Separator"); 83 return tabbedPane; 84 } 85 86 87 private DefaultFormBuilder buildPanelHeader() { 88 FormLayout layout = new FormLayout( 89 "right:pref, 3dlu, min:grow", 90 ""); 91 DefaultFormBuilder builder = new DefaultFormBuilder(layout); 92 builder.setDefaultDialogBorder(); 93 builder.setRowGroupingEnabled(true); 94 95 builder.appendSeparator("Customer Data"); 96 builder.append("Last Name", new JTextField()); 97 builder.append("First Name", new JTextField()); 98 builder.append("Street", new JTextField()); 99 builder.append("Email", new JTextField()); 100 101 return builder; 102 } 103 104 105 113 private JComponent buildCustomAreaWithAlignedLabelPanel() { 114 DefaultFormBuilder builder = buildPanelHeader(); 115 116 CellConstraints cc = new CellConstraints(); 117 118 builder.append("Feeback"); 119 builder.appendRow(new RowSpec("0:grow")); 120 builder.add(new JScrollPane(new JTextArea()), 121 cc.xywh(builder.getColumn(), builder.getRow(), 1, 2, "fill, fill")); 122 123 return builder.getPanel(); 124 } 125 126 127 131 private JComponent buildCustomAreaWithTopLabelPanel() { 132 DefaultFormBuilder builder = buildPanelHeader(); 133 134 CellConstraints cc = new CellConstraints(); 135 136 builder.appendRow(builder.getLineGapSpec()); 137 builder.appendRow(new RowSpec("top:pref:grow")); 138 builder.nextLine(2); 139 builder.append("Feedback"); 140 builder.add(new JScrollPane(new JTextArea()), 141 cc.xy(builder.getColumn(), builder.getRow(), "fill, fill")); 142 143 return builder.getPanel(); 144 } 145 146 147 156 private JComponent buildCustomAreaWithSeparatorPanel() { 157 DefaultFormBuilder builder = buildPanelHeader(); 158 159 builder.appendSeparator("Customer Feedback"); 160 builder.appendRow(builder.getLineGapSpec()); 161 builder.appendRow(new RowSpec("fill:pref:grow")); 162 builder.nextLine(2); 163 builder.append("", new JScrollPane(new JTextArea())); 164 165 return builder.getPanel(); 166 } 167 168 169 } | Popular Tags |