Current JButton and ActionListener on 'enter' key
843806May 6 2008 — edited May 8 2008Question 1 - How does Java know which JButton (or any object on a panel, for that matter) is currently selected?
For example, I have a 'yes/no' panel with a 'yes' button and a 'no' button. When the panel is launched, the 'yes' button is highlighted, and I can alternate between 'yes' and 'no' with the tab key. I can also use mnemonics on the 'y' key and the 'n' key. Does the panel initialise with the 'yes' button selected because the code for the 'yes' button occurs before the code for the 'no' button?
Question 2 - How do I write code that does something like "when you hit the enter key, doClick on the currently selected JButton"? At present, nothing happens when I hit the enter key. In order for this to work, it seems to me that the code needs to know which button is currently selected, hence Question 1.