Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to implement JTextArea in netbeans  RSS feed

 
Joe Don
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, perhaps I'm confused here. I have dragged and dropped a jTextArea from netbeans palette onto my form. But when I right clicked for Event > action > actionPerformed for implementation, I realized such was not there, unlike the jTextField component. Could someone educate me on how to achieve this? For example, I have tried this but it didn't work:

//{
Import java.swing.*;

JTextArea txa = new JTextArea();
txa.getText(jTextArea1);
txa.setText(jTextArea1);
txa.setTextWrap(true);

//}
 
Tony Docherty
Bartender
Posts: 3264
81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to get the Document and add a listener to that.
May I suggest you read the Java tutorial on using JTextArea http://docs.oracle.com/javase/tutorial/uiswing/components/textarea.html which explains all about this.
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ActionListener of a JTextField is invoked when you use the Enter key.

A JTextArea does not support the same concept. When you use the Enter key on a JTextArea a new line string is inserted into the Document.

If you tell us your actual requirement then we may be able to suggest a solution for you.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!