1 30 31 package com.jgoodies.forms.tutorial.basics; 32 33 import java.awt.Component ; 34 35 import javax.swing.*; 36 37 import com.jgoodies.forms.factories.Borders; 38 import com.jgoodies.forms.layout.CellConstraints; 39 import com.jgoodies.forms.layout.FormLayout; 40 41 47 public final class SpanExample { 48 49 public static void main(String [] args) { 50 try { 51 UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); 52 } catch (Exception e) { 53 } 55 JFrame frame = new JFrame(); 56 frame.setTitle("Forms Tutorial :: Span"); 57 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 58 JComponent panel = new SpanExample().buildPanel(); 59 frame.getContentPane().add(panel); 60 frame.pack(); 61 frame.show(); 62 } 63 64 65 71 public JComponent buildPanel() { 72 JTabbedPane tabbedPane = new JTabbedPane(); 73 tabbedPane.putClientProperty("jgoodies.noContentBorder", Boolean.TRUE); 74 75 tabbedPane.add("Column Span", buildColumnSpanExample()); 76 tabbedPane.add("Row Span", buildRowSpanExample()); 77 return tabbedPane; 78 } 79 80 81 86 private JComponent buildColumnSpanExample() { 87 FormLayout layout = new FormLayout( 88 "pref, 8px, 100px, 4px, 200px", 89 "pref, 6px, pref, 6px, pref, 6px, pref"); 90 91 JPanel panel = new JPanel(layout); 92 panel.setBorder(Borders.DIALOG_BORDER); 93 CellConstraints cc = new CellConstraints(); 94 95 panel.add(new JLabel("Name:"), cc.xy (1, 1)); 96 panel.add(new JTextField(), cc.xywh(3, 1, 3, 1)); 97 98 panel.add(new JLabel("Phone:"), cc.xy (1, 3)); 99 panel.add(new JTextField(), cc.xywh(3, 3, 3, 1)); 100 101 panel.add(new JLabel("ZIP/City:"), cc.xy (1, 5)); 102 panel.add(new JTextField(), cc.xy (3, 5)); 103 panel.add(new JTextField(), cc.xy (5, 5)); 104 105 panel.add(new JLabel("Country:"), cc.xy (1, 7)); 106 panel.add(new JTextField(), cc.xywh(3, 7, 3, 1)); 107 108 return panel; 109 } 110 111 112 125 private JComponent buildRowSpanExample() { 126 FormLayout layout = new FormLayout( 127 "200px, 25px, 200px", 128 "pref, 2px, pref, 9px, " + 129 "pref, 2px, pref, 9px, " + 130 "pref, 2px, pref"); 131 132 JPanel panel = new JPanel(layout); 133 panel.setBorder(Borders.DIALOG_BORDER); 134 CellConstraints cc = new CellConstraints(); 135 136 Component addressArea = new JScrollPane(new JTextArea()); 137 138 panel.add(new JLabel("Name"), cc.xy (1, 1)); 139 panel.add(new JTextField(), cc.xy (1, 3)); 140 141 panel.add(new JLabel("Phone"), cc.xy (1, 5)); 142 panel.add(new JTextField(), cc.xy (1, 7)); 143 144 panel.add(new JLabel("Fax"), cc.xy (1, 9)); 145 panel.add(new JTextField(), cc.xy (1, 11)); 146 147 panel.add(new JLabel("Notes"), cc.xy (3, 1)); 148 panel.add(addressArea, cc.xywh(3, 3, 1, 9)); 149 150 return panel; 151 } 152 153 154 } 155 156 | Popular Tags |