It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes Clearing JTextPane's Document! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Clearing JTextPane Watch "Clearing JTextPane New topic

Clearing JTextPane's Document!

Vic Hunting

Joined: Aug 06, 2003
Posts: 3
Hey Guys,
How do I clear a document associated with JTextPane?
I have a JTextPane displaying an html file which gets updated every second.
The way I have it below works brilliantly (doesn't flicker whatsoever) except that new content gets appended to the previous content.
Is there a way to clear the document just before the next iteration?

private class PageLoader extends TimerTask {
public PageLoader(){}
public void run() {
try {
//html is an instance of JTextPane
Document docs = html.getDocument();
InputStream input = new URL(string).openStream();
html.getEditorKit().read(input, docs, docs.getLength());

//Clear the document here:
}catch( Exception e ){
Joe Ess

Joined: Oct 29, 2001
Posts: 9190


[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Clearing JTextPane's Document!
It's not a secret anymore!