Listening to 2 Key Presses
This should be a fairly easy answer, but I cannot seem to find anything helpful on google.
I have a JTextArea that I want to provide the option to print. In order to activate that option, the user will press the standard: CTRL+P. How do I write a KeyListener to respond to the CTRL and P keys causing events?
Any help is appreciated.
Re: Listening to 2 Key Presses
Probably a better fit for a KeyBinding (see How to use KeyBindings) where you specify the KeyStroke as something like
Code :
KeyStroke.getKeyStroke("P",InputEvent.CTRL_MASK )
Re: Listening to 2 Key Presses
Ok, I don't understand how to get the Input Map. It just says:
Quote:
component.getInputMap().put(KeyStroke.getKeyStroke ("SPACE"),
"pressed");
for getting the component, and doesn't mention what component is for their examples. I tried to get the map to the JFrame, but it says it cannot find the symbol getInputMap(). I then tried to get the map for my ContentPane (which is a JScrollPane for this window) and I got the same error.
Re: Listening to 2 Key Presses
The method getInputMap() is defined in JComponent, so you can call the method on anything that is or extends this class (JFrame does not, JScrollPane does). If you continue to get the error you will have to post a more specific example that demonstrates the compiler error