Re: Input/action map prob on JTextComponent
- From: Karsten Wutzke <kwutzke@xxxxxx>
- Date: Thu, 20 Mar 2008 19:07:38 -0700 (PDT)
On 21 Mrz., 01:11, Karsten Wutzke <kwut...@xxxxxx> wrote:
Hello,
I use the following code to assign key strokes to actions to be
performed:
Action act = new ... (whatever)
JTextComponent tc = new ... (some standard text component)
Object key = action.getValue(Action.NAME);
tc.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
0), key); <--- not working!
tc.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
KeyEvent.CTRL_DOWN_MASK), key);
tc.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("alt
S"), key);
tc.getActionMap().put(key, caSend);
There's nothing basically wrong with the above code. When entering
something into the text component, the action atop is performed on Alt-
S or Ctrl-ENTER, however it is *NOT* performed when not using a
modifier. Might have to with the component being a text component. ->?
Why doesn't it work?
How do I make it work?
That text component is supposed to be single lined, but resizability
simply looks better with the app...
I've just tried using a JTextField instead and the RETURN only
keystroke *works*. Does anyone know why the former styled text pane/s
don't?
Karsten
Oops... the line
tc.getActionMap().put(key, caSend);
was supposed to be
tc.getActionMap().put(key, act);
Anyway the code is right and tested, since both other keystrokes
work...
Karsten
.
- References:
- Input/action map prob on JTextComponent
- From: Karsten Wutzke
- Input/action map prob on JTextComponent
- Prev by Date: Input/action map prob on JTextComponent
- Next by Date: Re: Images in text component (emoticons)
- Previous by thread: Input/action map prob on JTextComponent
- Index(es):