[SOLVED] Key binding Q
In a test app I bind(InputMap and ActionMap) the "UP,DOWN,RIGHT, and LEFT" arrow-keys to the main frame and set them to move the window(frame), so far it's working right, but if a TextField got focus, then it will consume the LEFT & RIGHT keys, and so the main window would not react (in this case move) to those keys.
Obviously this is the expected behaviour, but just for test, can I overright it to do the opposite? and/or allow both actions?
You can give the textfield's a null action: a string in the inputmap that does not correlate with one in the actionmap, and that may allow your mappings to work.
caveat: this has not been tested by me today but is from my crusty memory, so check it out first before assuming it's gospel!
Hello thanks, :)
Originally Posted by Fubarable
Yes this seems do the overrighting.... :cool:
Instead of the null act, I specify the same action...
However the thing I didn't like about it is that, if there were 10 textfields then do i have to create 10 map for them?
javax.swing.JRootPane rp = this.getRootPane();
InputMap imap = rp.getInputMap(
ActionMap amap = rp.getActionMap();
amap.put("LEFT", new ChangeLoc(3));
amap.put("RIGHT", new ChangeLoc(4));
InputMap imap2 = txtDummy.getInputMap();
ActionMap amap2 = txtDummy.getActionMap();
amap2.put("LEFT", new ChangeLoc(3));
amap2.put("RIGHT", new ChangeLoc(4));
Still need to figure out how to allow both actions.... i.e. window(frame) moves and TextField's caret position changes....
Found KeyEventDispatcher, it seems it can do what I'm looking for. :D
For just moving the window, redispach the event to the frame, and for both actions clone the event and then redispatch. working smoothly. :D