public Object getValueAt(int row, int column) { Parameter.MenuItem item = parameter.getMenuItems().get(row); if (column == 0) { return item.getKey(); } else { return item.getLabel(); } }
private MenuItemDialog(Dialog dialog, Parameter.MenuItem item) { super(dialog, "Menu Item", true); setResizable(false); setLocationByPlatform(true); JPanel content = new JPanel(new BorderLayout()); FormPanel form = new FormPanel(); keyField = new JTextField(item.getKey()); labelField = new JTextField(item.getLabel()); form.addRow("Key", keyField); form.addRow("Label", labelField); content.add(form, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 5, 0)); okButton = new JButton("OK"); okButton.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { // Commit key and label. successful = true; MenuItemDialog.this.setVisible(false); } }); cancelButton = new JButton("Cancel"); cancelButton.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { MenuItemDialog.this.setVisible(false); } }); buttonPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0)); buttonPanel.add(cancelButton); buttonPanel.add(okButton); content.add(buttonPanel, BorderLayout.SOUTH); setContentPane(content); content.setBorder(BorderFactory.createEmptyBorder(20, 40, 20, 20)); getRootPane().setDefaultButton(okButton); // Close window when escape key is pressed. getRootPane() .registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); pack(); }