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
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: 8710
    
    6

yourJTextPane.setText("");


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clearing JTextPane's Document!
 
Similar Threads
Text Plain and JTextPane
font family of empty DefaultStyledDocument
HTML text on SWING components
how to print the contents of jtextpane.
Unicode equivalent for <br>. Any idea?