Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing JTextArea Values

Status
Not open for further replies.

Magnus53

Programmer
Jul 25, 2002
73
CA
Hi everyone;

I'm trying to reset the values in a JTextArea component, I have this code but I keep getting exceptions when I run the code, could anyone take a look at see what is wrong?


Thanks

Code:

javax.swing.JTextArea myTa = (javax.swing.JTextArea) compTemp;
javax.swing.text.Element elm;
elm = myTa.getDocument().getDefaultRootElement();
int lineCount = elm.getElementCount();
System.out.println("TextArea element count" + lineCount);

for(int i = 0; i < lineCount; i++) {
javax.swing.text.Element e = elm.getElement(i);
int startPos = e.getStartOffset();
int endPos = e.getEndOffset();

try {
myTa.replaceRange(&quot;&quot;, startPos, endPos);
} catch (Exception ex) {
ex.printStackTrace();
}

}

}

and this is the exception:
java.lang.IllegalArgumentException: Invalid remove
at javax.swing.JTextArea.replaceRange(JTextArea.java:499)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top