Hello I’m trying to add the select-all, cut, copy and paste command in my application, I managed to work out the cut, copy and paste command but I don’t seem to have figured out how to add the cmd–a command…
this worked for my cmd–x command
text.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "cut");
but when I try this for cmd–a:
text.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "select");
it doesn’t seem to work…
I read something about using this void to select the text, but I don’t know how to bind it to the command+a command
myTextfield.selectAll();
Anyone got an idea on how to correctly implement this?
Use the correct
String:"select-all"instead of"select".You can discover these
Strings by investigating theInputMap, for example by using:which prints out (not the complete output pasted here)
This shows the
Stringyou are looking for is"select-all".Note that it might be really counter-intuitive for a user to switch the function of the ctrl key and the cmd key . For example on a Mac the cmd+A by default does select all (which is expected), but I would never expect that on a Windows/Linux machine