File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Clearing JTextPane Watch "Clearing JTextPane New topic
Author

Clearing JTextPane's Document!

Vic Hunting
Greenhorn

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?
cheers
:vic

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());

Thread.sleep(1000);
//Clear the document here:
}catch( Exception e ){
e.printStackTrace();
}
}
}
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8996
    
    9

yourJTextPane.setText("");


[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clearing JTextPane's Document!