Input/action map prob on JTextComponent

  • Follow


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
0
Reply kwutzke (87) 3/21/2008 12:11:31 AM

On 21 Mrz., 01:11, Karsten Wutzke <kwut...@web.de> 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

0
Reply Karsten 3/21/2008 2:07:38 AM


1 Replies
104 Views

(page loaded in 0.028 seconds)

Similiar Articles:













7/22/2012 8:35:14 AM


Reply: