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]
# 1
You don't need to do anything fancy, it should work just like you expect. Please post some code, there must be something else you're doing wrong.
BinaryDigita at 2007-7-12 20:30:35 > top of Java-index,Desktop,Core GUI APIs...
# 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);

camickra at 2007-7-12 20:30:35 > top of Java-index,Desktop,Core GUI APIs...
# 3
This may be a result of you using a MouseListener to handle your button clicks (common mistake) instead of using an ActionListener (preferred).The doClick() will fire the associated ActionListener.
KelVarnsona at 2007-7-12 20:30:35 > top of Java-index,Desktop,Core GUI APIs...
# 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 > top of Java-index,Desktop,Core GUI APIs...