1 30 31 package com.jgoodies.forms.tutorial.basics; 32 33 import javax.swing.*; 34 import javax.swing.border.EmptyBorder ; 35 36 import com.jgoodies.forms.builder.PanelBuilder; 37 import com.jgoodies.forms.extras.DefaultFormBuilder; 38 import com.jgoodies.forms.layout.CellConstraints; 39 import com.jgoodies.forms.layout.FormLayout; 40 41 50 public final class ComponentSizesExample { 51 52 53 public static void main(String [] args) { 54 try { 55 UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); 56 } catch (Exception e) { 57 } 59 JFrame frame = new JFrame(); 60 frame.setTitle("Forms Tutorial :: Component Sizes"); 61 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 62 JComponent panel = new ComponentSizesExample().buildPanel(); 63 frame.getContentPane().add(panel); 64 frame.pack(); 65 frame.show(); 66 } 67 68 69 public JComponent buildPanel() { 70 JSplitPane splitPane = new JSplitPane( 71 JSplitPane.HORIZONTAL_SPLIT, 72 true, 73 buildCombinedPanel(), 74 buildTextPanel()); 75 return splitPane; 76 } 77 78 79 82 private JComponent buildCombinedPanel() { 83 FormLayout layout = new FormLayout( 84 "30dlu:grow", 85 "pref, 3dlu, pref, 3dlu, pref"); 86 87 PanelBuilder builder = new PanelBuilder(layout); 88 builder.setDefaultDialogBorder(); 89 90 CellConstraints cc = new CellConstraints(); 91 92 builder.add(buildMinimumSizePanel(), cc.xy(1, 1)); 93 builder.add(buildDefaultSizePanel(), cc.xy(1, 3)); 94 builder.add(buildPreferredSizePanel(), cc.xy(1, 5)); 95 96 return builder.getPanel(); 97 } 98 99 100 private JComponent buildMinimumSizePanel() { 101 FormLayout layout = new FormLayout( 102 "right:max(25dlu;pref), 3dlu, min", 103 "pref"); 104 DefaultFormBuilder builder = new DefaultFormBuilder(layout); 105 builder.append("Min", new JTextField(15)); 106 return builder.getPanel(); 107 } 108 109 private JComponent buildDefaultSizePanel() { 110 FormLayout layout = new FormLayout( 111 "right:max(25dlu;pref), 3dlu, default", 112 "pref"); 113 DefaultFormBuilder builder = new DefaultFormBuilder(layout); 114 builder.append("Default", new JTextField(15)); 115 return builder.getPanel(); 116 } 117 118 private JComponent buildPreferredSizePanel() { 119 FormLayout layout = new FormLayout( 120 "right:max(25dlu;pref), 3dlu, pref", 121 "pref"); 122 DefaultFormBuilder builder = new DefaultFormBuilder(layout); 123 builder.append("Pref", new JTextField(15)); 124 return builder.getPanel(); 125 } 126 127 private JComponent buildTextPanel() { 128 JTextArea textArea = new JTextArea(5, 20); 129 textArea.setEditable(false); 130 textArea.setText("The text field used in the example on the left\n" + 131 "has a narrow minimum width and a wider preferred width.\n\n" + 132 "If you move the split divider to the left and right\n" + 133 "you can see how 'Default' shrinks the field if space is scarce.\n\n" + 134 "If there's not enough space for the preferred width\n" + 135 "the bottom field will be 'cut' on the right-hand side."); 136 JScrollPane scrollpane = new JScrollPane(textArea); 137 scrollpane.setBorder(new EmptyBorder (0, 0, 0, 0)); 138 return scrollpane; 139 } 140 141 142 } 143 144 | Popular Tags |