aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help with JTextArea" Watch "help with JTextArea" New topic
Author

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 (http://java.sun.com/j2se/1.4/docs/api/ first for any future questions.
-Stu
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Hi,
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.
Rene
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.
Jason
[ July 05, 2002: Message edited by: Jason Ford ]

SCJP, SCWCD
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:
cc.getTextArea().setEditable(true);
cc.getTextArea().copy();
cc.getTextArea().setEditable(false);
//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: http://aspose.com/file-tools
 
subject: help with JTextArea