Hello,
Scenario: A JFrame called myApplicationFrame contains aSplitPanel, which in turn contains aPanelA and aPanelB. aPanelA is empty right now, aPanelB contains a couple of buttons which have actions of their own to deal with using straightforward action events.
I would like that whilst the application is loaded, when the user presses the Up arrow on the keyboard, that no matter which component has focus (maybe a button in PanelB, maybe just the application's JFrame at GUI startup), at any point, PanelA.methodA is called.
Having read through the online documentation, I believe I need key bindings for the above... maybe something similar to below:
// instantiation of the jframe, split panes, and panels goes on previously //
myApplicationFrame.getInputMap().put(KeyStroke.getKeyStroke("Up"), "doAnAction");
myApplicationFrame.getActionMap().put("doAnAction", doAnAction);
Action doAnAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
System.out.println("Yay! It works - the user has pressed the keyboard button");
// call PanelA's methodA or something like that
}
};
The problem with this is that the methods getInputMap() and getActionMap() are "undefined for type JFrame".
So - I have tried to add this action code simply into PanelA's constructor... yet the consequence of this is that when PanelB's buttons have focus hitting the key on the keyboard does nothing. Thus, I can get this thing working using panels, but this doesn't give me "application-wide" calling of the method when the key is hit...
Could someone give me a few pointers on what I'm doing wrong, other strategies to attempt maybe?