Reputation: 129
For some kind of messenger application I am using a JTextArea so I can type in multiple lines. But after looking at the documentation I see there is no action event handler for this.
How can I enter text and when I press ENTER it shows up in a other text area? I wish to use no buttons for this
Regards.
Upvotes: 1
Views: 2135
Reputation: 1
// JTextArea txASend
// JTextArea txAReceive
// add the event "KeyTyped" to txASend
private void txASendKeyTyped(java.awt.event.KeyEvent evt) {
char c = evt.getKeyChar();
if(c == KeyEvent.VK_ENTER)
{
String msj = txASend.getText();
txAReceive.setText(msj);
}
}
Upvotes: 0
Reputation: 324118
The default Action when you use the Enter key is to add a "new line" string to the Document. If you don't like this behaviour then you need to replace this Action with your own custom Action.
Read up on Key Bindings to see how you might do this.
Upvotes: 4
Reputation: 2847
Did you try to hook a listener to key-change event raised by this control? I think it should work
Upvotes: 0