doClick() doesn't fire action
In response to catching an Enter (character) entered in a JTextArea, I want to programmatically click the Send button that's in the same JPanel.
Invoking <that btn>.doClick() doesn't do anything except make the btn look like it was clicked.
...altho' the documentation sure sounds like this is the thing to do
Do I have to somehow arrange for the mouse/cursor to be over the btn?
Do I have to get the btn the Focus?
Do I have to mung on the JTA's Action Map?
Thanks,
-- M.
[532 byte] By [
PMHa] at [2007-11-27 8:34:21]

# 2
Instead of creating two ActionListeners, a better approach is to create an Action that is shared by the button and the Enter KeyStroke. Read the Swing tutorial on "How to Use Actions" and "How to Use Key Bindings":
http://java.sun.com/docs/books/tutorial/uiswing/misc/index.html
The basic code would be:
Action action = ....
JButton button = new JButton(action);
textArea.getActionMap().put("insert-break", action);
# 4
Thank you all very much!
(Sorry I didn't back to this & you all more quickly; I was buried - and I didn't get my Watch set right.)
KelVarnson's right: I did use a MouseListener..
..&, although I haven't verified it yet, I'm expecting it to work when I change it to the preferred way.
...& I will then change to doing it the even more preferred way suggested by camickr.
(& BinaryDigit, we would've gotten there via your reply too, if I had been more attentive)
-- M.
pmha at 2007-7-12 20:30:35 >
