1 30 31 package com.jgoodies.forms.tutorial.basics; 32 33 import javax.swing.*; 34 35 import com.jgoodies.forms.factories.Borders; 36 import com.jgoodies.forms.layout.CellConstraints; 37 import com.jgoodies.forms.layout.FormLayout; 38 39 45 public final class GrowingExample { 46 47 48 public static void main(String [] args) { 49 try { 50 UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); 51 } catch (Exception e) { 52 } 54 JFrame frame = new JFrame(); 55 frame.setTitle("Forms Tutorial :: Growing"); 56 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 57 JComponent panel = new GrowingExample().buildPanel(); 58 frame.getContentPane().add(panel); 59 frame.pack(); 60 frame.show(); 61 } 62 63 64 public JComponent buildPanel() { 65 JTabbedPane tabbedPane = new JTabbedPane(); 66 tabbedPane.putClientProperty("jgoodies.noContentBorder", Boolean.TRUE); 67 68 tabbedPane.add("Horizontal 1", buildHorizontalGrowing1Panel()); 69 tabbedPane.add("Horizontal 2", buildHorizontalGrowing2Panel()); 70 tabbedPane.add("Horizontal 3", buildHorizontalGrowing3Panel()); 71 tabbedPane.add("Horizontal 4", buildHorizontalGrowing4Panel()); 72 tabbedPane.add("Vertical 1", buildVerticalGrowing1Panel()); 73 tabbedPane.add("Vertical 2", buildVerticalGrowing2Panel()); 74 return tabbedPane; 75 } 76 77 78 private JComponent buildHorizontalGrowing1Panel() { 79 FormLayout layout = new FormLayout( 80 "pref, 6px, pref:grow", 81 "pref, 12px, pref"); 82 83 JPanel panel = new JPanel(layout); 84 panel.setBorder(Borders.DIALOG_BORDER); 85 CellConstraints cc = new CellConstraints(); 86 87 panel.add(new JLabel("Fixed"), cc.xy(1, 1)); 88 panel.add(new JLabel("Gets all extra space"), cc.xy(3, 1)); 89 90 panel.add(new JTextField(5), cc.xy(1, 3)); 91 panel.add(new JTextField(5), cc.xy(3, 3)); 92 93 return panel; 94 } 95 96 97 private JComponent buildHorizontalGrowing2Panel() { 98 FormLayout layout = new FormLayout( 99 "pref, 6px, 0:grow, 6px, 0:grow", 100 "pref, 12px, pref"); 101 102 JPanel panel = new JPanel(layout); 103 panel.setBorder(Borders.DIALOG_BORDER); 104 CellConstraints cc = new CellConstraints(); 105 106 panel.add(new JLabel("Fixed"), cc.xy(1, 1)); 107 panel.add(new JLabel("Gets half of extra space"), cc.xy(3, 1)); 108 panel.add(new JLabel("gets half of extra space"), cc.xy(5, 1)); 109 110 panel.add(new JTextField(5), cc.xy(1, 3)); 111 panel.add(new JTextField(5), cc.xy(3, 3)); 112 panel.add(new JTextField(5), cc.xy(5, 3)); 113 114 return panel; 115 } 116 117 118 private JComponent buildHorizontalGrowing3Panel() { 119 FormLayout layout = new FormLayout( 120 "pref, 6px, 0:grow(0.25), 6px, 0:grow(0.75)", 121 "pref, 12px, pref"); 122 123 JPanel panel = new JPanel(layout); 124 panel.setBorder(Borders.DIALOG_BORDER); 125 CellConstraints cc = new CellConstraints(); 126 127 panel.add(new JLabel("Fixed"), cc.xy(1, 1)); 128 panel.add(new JLabel("Gets 25% of extra space"), cc.xy(3, 1)); 129 panel.add(new JLabel("Gets 75% of extra space"), cc.xy(5, 1)); 130 131 panel.add(new JTextField(5), cc.xy(1, 3)); 132 panel.add(new JTextField(5), cc.xy(3, 3)); 133 panel.add(new JTextField(5), cc.xy(5, 3)); 134 135 return panel; 136 } 137 138 139 private JComponent buildHorizontalGrowing4Panel() { 140 FormLayout layout = new FormLayout( 141 "pref:grow(0.33), 6px, pref:grow(0.67)", 142 "pref, 12px, pref"); 143 144 JPanel panel = new JPanel(layout); 145 panel.setBorder(Borders.DIALOG_BORDER); 146 CellConstraints cc = new CellConstraints(); 147 148 panel.add(new JLabel("Gets 33% of the space"), cc.xy(1, 1)); 149 panel.add(new JLabel("Gets 67% of the space"), cc.xy(3, 1)); 150 151 panel.add(new JTextField(5), cc.xy(1, 3)); 152 panel.add(new JTextField(5), cc.xy(3, 3)); 153 154 return panel; 155 } 156 157 private JComponent buildVerticalGrowing1Panel() { 158 FormLayout layout = new FormLayout( 159 "pref, 12px, pref", 160 "pref, 6px, fill:0:grow(0.25), 6px, fill:0:grow(0.75)"); 161 162 JPanel panel = new JPanel(layout); 163 panel.setBorder(Borders.DIALOG_BORDER); 164 CellConstraints cc = new CellConstraints(); 165 166 panel.add(new JLabel("Fixed"), cc.xy(1, 1)); 167 panel.add(new JLabel("Gets 25% of extra space"), cc.xy(1, 3)); 168 panel.add(new JLabel("Gets 75% of extra space"), cc.xy(1, 5)); 169 170 panel.add(createTextArea(4, 30), cc.xy(3, 1)); 171 panel.add(createTextArea(4, 30), cc.xy(3, 3)); 172 panel.add(createTextArea(4, 30), cc.xy(3, 5)); 173 174 return panel; 175 } 176 177 private JComponent buildVerticalGrowing2Panel() { 178 FormLayout layout = new FormLayout( 179 "pref, 12px, pref", 180 "fill:0:grow(0.25), 6px, fill:0:grow(0.75)"); 181 182 JPanel panel = new JPanel(layout); 183 panel.setBorder(Borders.DIALOG_BORDER); 184 CellConstraints cc = new CellConstraints(); 185 186 panel.add(new JLabel("Gets 25% of extra space"), cc.xy(1, 1)); 187 panel.add(new JLabel("Gets 75% of extra space"), cc.xy(1, 3)); 188 189 panel.add(createTextArea(4, 30), cc.xy(3, 1)); 190 panel.add(createTextArea(4, 30), cc.xy(3, 3)); 191 192 return panel; 193 } 194 195 196 198 private JComponent createTextArea(int rows, int cols) { 199 return new JScrollPane(new JTextArea(rows, cols), 200 ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, 201 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); 202 } 203 204 205 } 206 | Popular Tags |