1 30 31 package com.jgoodies.forms.tutorial.basics; 32 33 import javax.swing.*; 34 35 import com.jgoodies.forms.builder.PanelBuilder; 36 import com.jgoodies.forms.layout.CellConstraints; 37 import com.jgoodies.forms.layout.FormLayout; 38 39 45 public final class BoundedSizesExample { 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 :: Bounded Sizes"); 56 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 57 JComponent panel = new BoundedSizesExample().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("Jumping 1", buildJumping1Panel()); 69 tabbedPane.add("Jumping 2", buildJumping2Panel()); 70 tabbedPane.add("Stable 1", buildStable1Panel()); 71 tabbedPane.add("Stable 2", buildStable2Panel()); 72 return tabbedPane; 73 } 74 75 76 private JComponent buildJumping1Panel() { 77 FormLayout layout = new FormLayout( 78 "right:pref, 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ", 79 EDITOR_ROW_SPEC); 80 return buildEditorGeneralPanel(layout); 81 } 82 83 private JComponent buildJumping2Panel() { 84 FormLayout layout = new FormLayout( 85 "right:pref, 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ", 86 EDITOR_ROW_SPEC); 87 return buildEditorTransportPanel(layout); 88 } 89 90 private JComponent buildStable1Panel() { 91 FormLayout layout = new FormLayout( 92 "right:max(50dlu;pref), 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ", 93 EDITOR_ROW_SPEC); 94 return buildEditorGeneralPanel(layout); 95 } 96 97 private JComponent buildStable2Panel() { 98 FormLayout layout = new FormLayout( 99 "right:max(50dlu;pref), 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ", 100 EDITOR_ROW_SPEC); 101 return buildEditorTransportPanel(layout); 102 } 103 104 private static final String EDITOR_ROW_SPEC = 105 "p, 3dlu, p, 3dlu, p, 3dlu, p"; 106 107 108 111 private JComponent buildEditorGeneralPanel(FormLayout layout) { 112 layout.setColumnGroups(new int[][] { { 3, 5, 7, 9 } }); 113 PanelBuilder builder = new PanelBuilder(layout); 114 115 builder.setDefaultDialogBorder(); 116 CellConstraints cc = new CellConstraints(); 117 118 builder.addLabel("File number:", cc.xy (1, 1)); 119 builder.add(new JTextField(), cc.xywh(3, 1, 7, 1)); 120 builder.addLabel("RFQ number:", cc.xy (1, 3)); 121 builder.add(new JTextField(), cc.xywh(3, 3, 7, 1)); 122 builder.addLabel("Entry date:", cc.xy (1, 5)); 123 builder.add(new JTextField(), cc.xy (3, 5)); 124 builder.addLabel("Sales Person:", cc.xy (1, 7)); 125 builder.add(new JTextField(), cc.xywh(3, 7, 7, 1)); 126 127 return builder.getPanel(); 128 } 129 130 133 private JComponent buildEditorTransportPanel(FormLayout layout) { 134 layout.setColumnGroups(new int[][] { { 3, 5, 7, 9 } }); 135 PanelBuilder builder = new PanelBuilder(layout); 136 137 builder.setDefaultDialogBorder(); 138 CellConstraints cc = new CellConstraints(); 139 140 builder.addLabel("Shipper:", cc.xy (1, 1)); 141 builder.add(new JTextField(), cc.xy (3, 1)); 142 builder.add(new JTextField(), cc.xywh(5, 1, 5, 1)); 143 builder.addLabel("Consignee:", cc.xy (1, 3)); 144 builder.add(new JTextField(), cc.xy (3, 3)); 145 builder.add(new JTextField(), cc.xywh(5, 3, 5, 1)); 146 builder.addLabel("Departure:", cc.xy (1, 5)); 147 builder.add(new JTextField(), cc.xy (3, 5)); 148 builder.add(new JTextField(), cc.xywh(5, 5, 5, 1)); 149 builder.addLabel("Destination:", cc.xy (1, 7)); 150 builder.add(new JTextField(), cc.xy (3, 7)); 151 builder.add(new JTextField(), cc.xywh(5, 7, 5, 1)); 152 153 return builder.getPanel(); 154 } 155 156 157 158 159 } 160 161 | Popular Tags |