1 30 31 package com.jgoodies.forms.tutorial.factories; 32 33 import java.awt.Component ; 34 35 import javax.swing.*; 36 37 import com.jgoodies.forms.extras.DefaultFormBuilder; 38 import com.jgoodies.forms.factories.FormFactory; 39 import com.jgoodies.forms.layout.ColumnSpec; 40 import com.jgoodies.forms.layout.FormLayout; 41 import com.jgoodies.forms.layout.Sizes; 42 43 51 public final class FormFactoryExample { 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 :: FormFactory"); 61 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 62 JComponent panel = new FormFactoryExample().buildPanel(); 63 frame.getContentPane().add(panel); 64 frame.pack(); 65 frame.show(); 66 } 67 68 public JComponent buildPanel() { 69 JTabbedPane tabbedPane = new JTabbedPane(); 70 tabbedPane.putClientProperty("jgoodies.noContentBorder", Boolean.TRUE); 71 72 tabbedPane.add(buildDefaultForm(1, 1), "1 - 1"); 73 tabbedPane.add(buildDefaultForm(1, 2), "1 - 2"); 74 tabbedPane.add(buildDefaultForm(1, 3), "1 - 3"); 75 tabbedPane.add(buildDefaultForm(2, 1), "2 - 1"); 76 tabbedPane.add(buildDefaultForm(2, 2), "2 - 2"); 77 tabbedPane.add(buildDefaultForm(3, 1), "3 - 1"); 78 return tabbedPane; 79 } 80 81 82 private Component buildDefaultForm(int majorCols, int minorCols) { 83 FormLayout layout = 84 FormFactory.createColumnLayout( 85 majorCols, 86 minorCols, 87 new ColumnSpec("right:p"), 88 Sizes.DLUX9, 89 Sizes.DLUX1); 90 91 DefaultFormBuilder builder = new DefaultFormBuilder(layout); 92 builder.setDefaultDialogBorder(); 93 builder.setLeadingColumnOffset(1); 94 95 buildParagraph(builder, 4, majorCols, minorCols, "Propeller Shaft"); 96 buildParagraph(builder, 3, majorCols, minorCols, "Intermediate Shaft"); 97 98 return builder.getContainer(); 99 } 100 101 private void buildParagraph( 102 DefaultFormBuilder builder, 103 int rows, 104 int majorCols, 105 int minorCols, 106 String text) { 107 builder.appendSeparator(text); 108 for (int row = 0; row < rows; row++) { 109 buildRow(builder, majorCols, minorCols); 110 } 111 } 112 113 private void buildRow( 114 DefaultFormBuilder builder, 115 int majorCols, 116 int minorCols) { 117 int charCols = 50 / (majorCols * (1 + minorCols)); 118 for (int majorCol = 0; majorCol < majorCols; majorCol++) { 119 buildSection(builder, minorCols, charCols); 120 } 121 builder.nextLine(); 122 } 123 124 private void buildSection(DefaultFormBuilder builder, int minorCols, int charCols) { 125 builder.append(nextLabel(), new JTextField(charCols)); 126 for (int minorCol = 1; minorCol < minorCols; minorCol++) { 127 builder.append(new JTextField(charCols)); 128 } 129 } 130 131 133 private static int nextInt = 0; 134 135 private String nextLabel() { 136 if (nextInt++ == LABELS.length - 1) 137 nextInt = 0; 138 return LABELS[nextInt]; 139 } 140 141 private static final String [] LABELS = { 142 "da [mm]", "ds [mm]", "kl [cm]", "Weight [Kg]", "Size [mm]", 143 "da2 [mm]", "ds2 [mm]", "cv [cm]", "pl [cm]", "mt [mm]", 144 "ep [mm]", "cvn [mm]", "nz [cm]", "Power [kW]", "Length [cm]", 145 "R [cm]", "D [mm]", "PTI [kW]" 146 }; 147 148 } 149 | Popular Tags |