I'm working on a GUI.
The Gui is constructed as follows: A JFrame containining a (custom) leftPanel and rightPanel. RightPanel is an extension of a tabbedpane and contains as one of the tabs, the class MainTab.
Maintab has the following code:
private void createKeyBindings(){
actionMap = this.getActionMap();
inputMap = this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(KeyStroke.getKeyStroke("UP),
"pressedUpArrow");
inputMap.put(KeyStroke.getKeyStroke("released UP"),
"releasedUpArrow");
actionMap.put("pressedUpArrow",
new PressedUpArrowAction());
actionMap.put("releasedUpArrow",
new ReleasedUpArrowAction());
inputMap.put(KeyStroke.getKeyStroke("RIGHT"),
"pressedRightArrow");
inputMap.put(KeyStroke.getKeyStroke("released RIGHT"),
"releasedRightArrow");
actionMap.put("pressedRightArrow",
new PressedRightArrowAction());
actionMap.put("releasedRightArrow",
new ReleasedRightArrowAction());
inputMap.put(KeyStroke.getKeyStroke("LEFT"),
"pressedLeftArrow");
inputMap.put(KeyStroke.getKeyStroke("released LEFT"),
"releasedLeftArrow");
actionMap.put("pressedLeftArrow",
new PressedLeftArrowAction());
actionMap.put("releasedLeftArrow",
new ReleasedLeftArrowAction());
inputMap.put(KeyStroke.getKeyStroke("RIGHT"),
"pressedRightArrow");
inputMap.put(KeyStroke.getKeyStroke("released RIGHT"),
"releasedRightArrow");
actionMap.put("pressedRightArrow",
new PressedRightArrowAction());
actionMap.put("releasedRightArrow",
new ReleasedRightArrowAction());
inputMap.put(KeyStroke.getKeyStroke("DOWN"),
"pressedDownArrow");
inputMap.put(KeyStroke.getKeyStroke("released DOWN"),
"releasedDownArrow");
actionMap.put("pressedDownArrow",
new PressedDownArrowAction());
actionMap.put("releasedDownArrow",
new ReleasedDownArrowAction());
}
So, it has to undertake an action when I press one of the arrow keys, and when I release it.
But it only does something when I release one of the arrow keys. The cause is probably that one of the other components of LeftPanel or RightPanel or the panels itself already use that keybinding for something else.
I've tried to just clear the inputmaps and actionmaps in the classes themselves ( this.getInputMap().clear() ), but the problem remains. Any solutions?