H
Hendrik Maryns
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
In my Swing app, I define a default button like so:
// make submit the default action
SwingUtilities.getRootPane(submitButton).setDefaultButton(submitButton);
The submit button submits some query. This seems to work fine: if I hit
enter the selected query in the UI is submitted.
However, I also want another action, editAction to be associated with
Ctrl+Enter, to let the user edit the query. I do the following:
private Action createEditAction() {
~ final Action editAction = new AbstractAction() {
~ public void actionPerformed(final ActionEvent evt) {
~ // let the user edit the currently selected query
~ }
~ };
~ editAction.putValue(Action.NAME, "Edit formula…");
~ editAction.putValue(Action.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK));
~ editAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_E);
~ return editAction;
}
and later, I associate it with a menu item and ad that to a menu:
final JMenuItem editItem = new JMenuItem(editAction);
editMenu.add(editItem);
For other actions I have defined like this (like Open file, Save etc.),
this works fine, with shortcuts like Ctrl+O, Ctrl+S. But Ctrl+Enter
executes the action associated to the default button, instead of the
edit action. What am I doing wrong here?
Cheers, H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD4DBQFIToRre+7xMGD3itQRAh0SAJdX+Rv3EYCCym7Zv5qXENEN8Of4AJ9+BqJB
WJpKtAE2NpYVOEaNpwyAjQ==
=RROz
-----END PGP SIGNATURE-----
Hash: SHA1
Hi all,
In my Swing app, I define a default button like so:
// make submit the default action
SwingUtilities.getRootPane(submitButton).setDefaultButton(submitButton);
The submit button submits some query. This seems to work fine: if I hit
enter the selected query in the UI is submitted.
However, I also want another action, editAction to be associated with
Ctrl+Enter, to let the user edit the query. I do the following:
private Action createEditAction() {
~ final Action editAction = new AbstractAction() {
~ public void actionPerformed(final ActionEvent evt) {
~ // let the user edit the currently selected query
~ }
~ };
~ editAction.putValue(Action.NAME, "Edit formula…");
~ editAction.putValue(Action.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK));
~ editAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_E);
~ return editAction;
}
and later, I associate it with a menu item and ad that to a menu:
final JMenuItem editItem = new JMenuItem(editAction);
editMenu.add(editItem);
For other actions I have defined like this (like Open file, Save etc.),
this works fine, with shortcuts like Ctrl+O, Ctrl+S. But Ctrl+Enter
executes the action associated to the default button, instead of the
edit action. What am I doing wrong here?
Cheers, H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD4DBQFIToRre+7xMGD3itQRAh0SAJdX+Rv3EYCCym7Zv5qXENEN8Of4AJ9+BqJB
WJpKtAE2NpYVOEaNpwyAjQ==
=RROz
-----END PGP SIGNATURE-----