This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes help with JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help with JTextArea" Watch "help with JTextArea" New topic

help with JTextArea

kevin comario
Ranch Hand

Joined: Jun 29, 2002
Posts: 65
Does anyone know how set a JTextArea to be uneditable, except for what i append to it. Sort of like chat program where you can the lower part can be edited but the top cannot be deleted cut or modified.
any help is appreciated.
Stu Glassman
Ranch Hand

Joined: Jul 01, 2002
Posts: 91
JTextArea has a method named setEditable. It takes one parameter, a boolean.
I'd suggest having a look at the Java 2 API ( first for any future questions.
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
setEditable won't be a solution, because it sets the whole content, but this wasn't asked. Kevin wants to set only a part of the JTextArea. And I think this will not work. It seems to me, that you need two JTestAreas instead of one.
Jason Ford
Ranch Hand

Joined: Aug 02, 2001
Posts: 54
Does anyone know how to set a JTextArea to be uneditable, except for what i append to it?

The answer is: it depends. If you intend to update the JTextArea with its append method, you are free to do so even if the setEditable( false ) method has been called on it. The setEditable method prevents the user, not the programmer, from appending to the JTextArea.
If you want the functionality of a chat program, you could set up the GUI like this:

The user enters a string into the JTextField, and a listener waits for the ENTER key. When it hears the ENTER key, the listener updates the JTextArea using the append method.
[ July 05, 2002: Message edited by: Jason Ford ]

kevin comario
Ranch Hand

Joined: Jun 29, 2002
Posts: 65
thanks everyone you were a big help
kevin comario
Ranch Hand

Joined: Jun 29, 2002
Posts: 65
I have one more question, i have created the gui and got everything to work fine but i have one problem i want the user to be able to copy from the JTextArea but not be able to do anything else,
the way that i have tried it so far is:
//my text area starts of setEditable(false);
it allows the user to copy but not edit the text except for one side effect the user can paste on the text area for some reason. How do i set it so that you cannot paste in my text area? Is there a way to disable paste?
Thanks in advance.
I agree. Here's the link:
subject: help with JTextArea
It's not a secret anymore!