• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to enable CTRL+C to perform action instead of coping to clipboard?  RSS feed

 
Vedrana Veric
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does someone know how to disable that CTRL+C performs normal
copy to clipboard. I have an application and on CTRL+C I want to
perform some defined action. If I bind some other keystroke
to my action it works, but with CTRL+C, CTRL+X and CTRL+V
I have normal windows copy/cut/paste behaviour.
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To remove a keyboard binding from an individual component, replace its entry in the component's InputMap with an invalid action name:For more on keyboard bindings, see this article (skip down to the section "JDK 1.3 Keyboard Bindings Infrastructure"):

http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html
[ October 25, 2005: Message edited by: Alan Moore ]
 
Vedrana Veric
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't found solution there, I don't want to remove key binding
but to use ctrl-c for specific copy action. I have in popup window defined copy action and ctrl-c is binded to that action. If I open popup
and then press ctrl-c my copy action is triggered, but if I press ctrl-c without opening popup than my action isn't catched, everything is
copied to clipboard.
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How exactly are you binding "ctrl C" to your copy action?
 
Vedrana Veric
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keystroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK) is asigned to copyAction,
copyAction is added to ActionMap, map is bound on table on which I want to
perform copy action (and other actions too) and ActionListener is set. This process is implemented long time ago(not by me) and it works for everything but this 3 specific shortcuts.
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this being done in the JTable's InputMap/ActionMap? Is it the WHEN_ANCESTOR_OF_FOCUSED_COMPONENT InputMap? If you're getting it by calling table.getInputMap(), it's the WHEN_FOCUSED InputMap you're working with, and that's the wrong one.
 
Vedrana Veric
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is JTable InputMap/ActionMap. InputMap is WHEN_IN_FOCUSED_WINDOW.

InputMap compImap = component.getInputMapJComponent.WHEN_IN_FOCUSED_WINDOW);

With WHEN_ANCESTOR_OF_FOCUSED_COMPONENT also doesn't work.
 
Vedrana Veric
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you maybe have some example how this should be set?
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I understand it, JTable should only be using the WHEN_ANCESTOR_etc InputMap. I used the following code to replace the JTable's Cut action in a demo app, and it worked fine.
 
Vedrana Veric
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for help, it works
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!