/** @return file chooser in dialog */ public Component getCustomEditor() { final JFileChooser chooser = createFileChooser(); final javax.swing.JDialog dialog = new javax.swing.JDialog( TopManager.getDefault().getWindowManager().getMainWindow(), chooser.getDialogTitle(), true); // attach cancel also to Escape key dialog .getRootPane() .registerKeyboardAction( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { dialog.setVisible(false); dialog.dispose(); } }, javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, true), javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW); dialog.addKeyListener( new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) { dialog.setVisible(false); dialog.dispose(); } } }); dialog.getContentPane().setLayout(new java.awt.BorderLayout()); dialog.getContentPane().add(chooser, java.awt.BorderLayout.CENTER); chooser.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { if (JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) { File f = chooser.getSelectedFile(); setValue(f); dialog.setVisible(false); dialog.dispose(); } else if (JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) { dialog.setVisible(false); dialog.dispose(); } } }); HelpCtx.setHelpIDString(dialog.getRootPane(), getHelpCtx().getHelpID()); return dialog; }
public static void removeEnterFromKeymap(javax.swing.JTextField field) { javax.swing.KeyStroke enter = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, 0); javax.swing.text.Keymap map = field.getKeymap(); map.removeKeyStrokeBinding(enter); }