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 BasicSizesExample { 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 :: Basic Sizes"); 56 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 57 JComponent panel = new BasicSizesExample().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", buildHorizontalSizesPanel()); 69 tabbedPane.add("Vertical", buildVerticalSizesPanel()); 70 return tabbedPane; 71 } 72 73 74 private JComponent buildHorizontalSizesPanel() { 75 FormLayout layout = new FormLayout( 76 "pref, 12px, " + "75px, 25px, min, 25px, pref", 77 "pref, 12px, pref"); 78 79 JPanel panel = new JPanel(layout); 81 82 panel.setBorder(Borders.DIALOG_BORDER); 84 85 CellConstraints cc = new CellConstraints(); 87 88 panel.add(new JLabel("75px"), cc.xy(3, 1)); 90 panel.add(new JLabel("Min"), cc.xy(5, 1)); 91 panel.add(new JLabel("Pref"), cc.xy(7, 1)); 92 93 panel.add(new JLabel("new JTextField(15)"), cc.xy(1, 3)); 94 95 panel.add(new JTextField(15), cc.xy(3, 3)); 96 panel.add(new JTextField(15), cc.xy(5, 3)); 97 panel.add(new JTextField(15), cc.xy(7, 3)); 98 99 return panel; 100 } 101 102 103 private JComponent buildVerticalSizesPanel() { 104 FormLayout layout = new FormLayout( 105 "pref, 12px, pref", 106 "pref, 12px, 45px, 12px, min, 12px, pref"); 107 108 JPanel panel = new JPanel(layout); 110 111 panel.setBorder(Borders.DIALOG_BORDER); 113 114 CellConstraints cc = new CellConstraints(); 116 117 panel.add(new JLabel("new JTextArea(10, 40)"), cc.xy(3, 1)); 119 120 panel.add(new JLabel("45px"), cc.xy(1, 3)); 121 panel.add(new JLabel("Min"), cc.xy(1, 5)); 122 panel.add(new JLabel("Pref"), cc.xy(1, 7)); 123 124 panel.add(createTextArea(10, 40), cc.xy(3, 3)); 125 panel.add(createTextArea(10, 40), cc.xy(3, 5)); 126 panel.add(createTextArea(10, 40), cc.xy(3, 7)); 127 128 return panel; 129 } 130 131 private JComponent createTextArea(int rows, int cols) { 132 return new JScrollPane(new JTextArea(rows, cols), 133 ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, 134 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); 135 } 136 137 138 140 145 183 184 } 185 186 | Popular Tags |