Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with JTextArea

 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks everyone you were a big help
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic