Java Reference
In-Depth Information
24
25 // right justify the numeric field
26 amntField.setHorizontalAlignment(JTextField.RIGHT);
27
28 // TODO: so that <Enter> will do a create
29 // this.getInputMap().put(KeyStroke.getKeyStroke("Enter"), "create");
30 /*
31 Action myAction = new AbstractAction("doSomething") {
32 public void actionPerformed() {
33 doSomething();
34 }
35 };
36 myComponent.getActionMap().put(myAction.get(Action.NAME), myAction);
37 */
38
39 //--------------------------------------------------Label on top----
40 JLabel label = new JLabel("<html><p align=left><i>"
41 + "Enter the info to create a subaccount.<br>"
42 + "</i>");
43 label.setHorizontalAlignment(JLabel.LEFT);
44 Font font = label.getFont();
45 label.setFont(label.getFont().deriveFont(font.PLAIN, 14.0f));
46
47 //--------------------------------------------------Text Fields-----
48 String[] labels = {"(Sub)Account Name: ", "Dollar Amount: "};
49 JTextField [] fields = {nameField, amntField};
50 int numPairs = fields.length;
51
52 //Create and populate the panel.
53 JPanel textes = new JPanel(new SpringLayout());
54 for (int i = 0; i < numPairs; i++) {
55 JLabel l = new JLabel(labels[i], JLabel.TRAILING);
56 textes.add(l);
57 l.setLabelFor(fields[i]); // not nec. since we have no kb shortcuts
58 textes.add(fields[i]);
59 }
60
61 //Lay out the panel.
62 SpringUtilities.makeCompactGrid(textes,
63 numPairs, 2, //rows, cols
64 6, 6, //initX, initY
65 6, 6); //xPad, yPad
66
67
68 //--------------------------------------------------Buttons on bottom
69 JButton createButton = new JButton("Create");
70 createButton.addActionListener(new ActionListener() {
71 public void actionPerformed(ActionEvent e) {
72 nameField.grabFocus(); // before leaving, ready for next time.
Search WWH ::




Custom Search