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 GroupingExample { 46 47 public static void main(String [] args) { 48 try { 49 UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); 50 } catch (Exception e) { 51 } 53 JFrame frame = new JFrame(); 54 frame.setTitle("Forms Tutorial :: Grouping"); 55 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 56 JComponent panel = new GroupingExample().buildPanel(); 57 frame.getContentPane().add(panel); 58 frame.pack(); 59 frame.show(); 60 } 61 62 63 public JComponent buildPanel() { 64 JTabbedPane tabbedPane = new JTabbedPane(); 65 tabbedPane.putClientProperty("jgoodies.noContentBorder", Boolean.TRUE); 66 67 tabbedPane.add("Ungrouped Bar", buildWizardBar(false)); 68 tabbedPane.add("Grouped Bar", buildWizardBar(true)); 69 tabbedPane.add("Ungrouped Rows", buildEditorPanel(false)); 70 tabbedPane.add("Grouped Rows", buildEditorPanel(true)); 71 return tabbedPane; 72 } 73 74 75 private JComponent buildWizardBar(boolean grouped) { 76 FormLayout layout = new FormLayout( 77 "pref, 6px:grow, pref, pref, 12px, pref, 6px, pref", 78 "pref"); 79 if (grouped) { 80 layout.setColumnGroups(new int[][]{{1, 3, 4, 6, 8}}); 81 } 82 JPanel panel = new JPanel(layout); 83 panel.setBorder(Borders.DIALOG_BORDER); 84 CellConstraints cc = new CellConstraints(); 85 86 panel.add(createNarrowButton("Hilfe"), cc.xy(1, 1)); 87 panel.add(createNarrowButton("< Zurück"), cc.xy(3, 1)); 88 panel.add(createNarrowButton("Vor >"), cc.xy(4, 1)); 89 panel.add(createNarrowButton("Beenden"), cc.xy(6, 1)); 90 panel.add(createNarrowButton("Abbrechen"), cc.xy(8, 1)); 91 92 return panel; 93 } 94 95 96 private JComponent buildEditorPanel(boolean grouped) { 97 FormLayout layout = new FormLayout( 98 "pref, 4dlu, 35dlu, 2dlu, 35dlu, 2dlu, 35dlu, 2dlu, 35dlu", 99 "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p"); 100 if (grouped) { 101 layout.setRowGroups(new int[][] { { 1, 3, 5, 7, 9, 11, 13, 15, 17 } }); 102 } 103 104 JPanel panel = new JPanel(layout); 105 panel.setBorder(Borders.DIALOG_BORDER); 106 CellConstraints cc = new CellConstraints(); 107 108 panel.add(new JLabel("File number:"), cc.xy (1, 1)); 109 panel.add(new JTextField(), cc.xywh(3, 1, 7, 1)); 110 panel.add(new JLabel("BL/MBL number:"), cc.xy (1, 3)); 111 panel.add(new JTextField(), cc.xy (3, 3)); 112 panel.add(new JTextField(), cc.xy (5, 3)); 113 panel.add(new JLabel("Entry date:"), cc.xy (1, 5)); 114 panel.add(new JTextField(), cc.xy (3, 5)); 115 panel.add(new JLabel("RFQ number:"), cc.xy (1, 7)); 116 panel.add(new JTextField(), cc.xywh(3, 7, 7, 1)); 117 panel.add(new JLabel("Goods:"), cc.xy (1, 9)); 118 panel.add(new JCheckBox("Dangerous"), cc.xywh(3, 9, 7, 1)); 119 panel.add(new JLabel("Shipper:"), cc.xy (1, 11)); 120 panel.add(new JTextField(), cc.xywh(3, 11, 7, 1)); 121 panel.add(new JLabel("Customer:"), cc.xy (1, 13)); 122 panel.add(new JTextField(), cc.xywh(3, 13, 5, 1)); 123 panel.add(new JButton("..."), cc.xy (9, 13)); 124 panel.add(new JLabel("Port of loading:"), cc.xy (1, 15)); 125 panel.add(new JTextField(), cc.xywh(3, 15, 7, 1)); 126 panel.add(new JLabel("Destination:"), cc.xy (1, 17)); 127 panel.add(new JTextField(), cc.xywh(3, 17, 7, 1)); 128 129 return panel; 130 } 131 132 133 135 private JButton createNarrowButton(String text) { 136 JButton button = new JButton(text); 137 button.putClientProperty("jgoodies.isNarrow", Boolean.TRUE); 138 return button; 139 } 140 141 142 } 143 144 | Popular Tags |