开发者

How to use enter instead of a button JTextArea?

开发者 https://www.devze.com 2023-01-28 19:59 出处:网络
For some kind of messenger application I am using a JT开发者_如何学运维extArea so I can type in multiple lines. But after looking at the documentation I see there is no action event handler for this.

For some kind of messenger application I am using a JT开发者_如何学运维extArea 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.


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.


Did you try to hook a listener to key-change event raised by this control? I think it should work


// 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);
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号