• Post Reply Bookmark Topic Watch Topic
  • New Topic

Action accelerator  RSS feed

 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any please tell me why pressing CTRL-ENTER does not fire an action event?

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're adding it to the toolbar only, so I'd guess (not being familiar with toolbars and their behavior) that at the very least the cursor needs to be on top of the toolbar, or the toolbar needs to be 'activated' in some way.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if the toolbar has focus, no action event is fired.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the javadocs this creates a new JButton, which you don't seem to use. Maybe that's the problem? I'm just speculating here.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it works OK if attached to a menuItem - perhaps that's the only place accelerators work??

also works OK, if changed to a mnemonic
putValue(MNEMONIC_KEY, VK_ENTER);
but then it's ALT-ENTER to trigger
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Buttons don't add the bindings for keyboard accelerators like JMenus do. Note that if you call JRootPane.setDefaultButton(JButton button) most UI's will cause ctrl-enter to fire the indicated button. If you want more flexibility, you'll have to add the action to some InputMap manually.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!