Detecting KeyBoard events on a JDialog
- From: denzel <denzel@xxxxxxxxxxxxxx>
- Date: Mon, 30 Oct 2006 13:02:19 +0100
Hello,
i have a JDialog subclass, with a lot of components in it, and i would like to detect Ctrl+C on it. I've tried to use this:
protected void register(JComponent jcomp) {
Action action = new AbstractAction("Action") {
public void actionPerformed(ActionEvent evt) {
System.err.println("Action!!!");
}
};
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK);
jcomp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(key, "myaction");
jcomp.getInputMap(JComponent.WHEN_FOCUSED).put(key, "myaction");
jcomp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(key, "myaction");
jcomp.getActionMap().put("myaction", action);
}
wich is call like that:
register((JComponent)getContentPane());
register((JComponent)getGlassPane());
register(getRootPane());
but my action is never performed.
So i've registered a KeyListener recursively on my dialog, and the keylistener is called with getSource() returning the dialog ref. But the dialog has no inputMap so how can i do?
I can't use the recursive trick because there are 2 JTables in the Dialog which must keep its default copy behavior, and a lot of text fields too.
Thanks for any help.
.
- Prev by Date: How to show the table and not the string in struts
- Next by Date: Re: No keyboard into in JApplet
- Previous by thread: How to show the table and not the string in struts
- Next by thread: charting package
- Index(es):