aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes too much text in textpane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "too much text in textpane" Watch "too much text in textpane" New topic
Author

too much text in textpane

Alex Wolf
Greenhorn

Joined: Aug 24, 2004
Posts: 16
Hi, Im writing a messenger, and I'm experiencing a problem with too much text in JTextPanes. That means, the more messages I receive, the slower the messenger reacts because there's so much text in the JTextPane. This goes to the point of it being unusable. I usually fix this by closing the window and reopening it so that there's no text to display. This works for a while, but its annoying.

I want fix this by setting the JTextPane to display up to a certain number of lines, for example 200, and everything thats exceeds this, should be written to a file so that I can recall it if the user chooses to scroll to the top.
When receiving messages, the text is formatted and then added to the JTextPane and when recalling it should be formatted the same way.

I need some help getting started. I don't know how to extract the formatted text from the JTextPane.
Its easy to set text with html formatting:

but retrieving the text just gives me plain text.
Jared Cope
Ranch Hand

Joined: Aug 18, 2004
Posts: 243
Hi,

Basically, you will need to become familar with 3 main objects:
1. The textPane
2. The editorKit for the textPane
3. The document object that sits behind the textPane

There are a few good tutorials around that walk you through it all. The learning curve is a bit steep, but there really is no other way. All the interesting stuff happens in the document object and the editorKit that the textPane uses. It sounds like you will need to extend the editorKit class and over-ride some of the insert methods to get your '200 lines' function working.

To speed ahead, you should learn about how the document is made up of a number of elements. Elements have their special properties such as formatting and colouring (markup in HTML terms). Your best bet is to traverse the document object and get all the elements then have a peak at their properties. You will probably learn a lot from that.

Jumping ahead, if you want to see the markup behind a textpane, try calling the dump method of the Document. Just use System.out as the argument to dump to your console.

Hope this has helped you.

Cheers, Jared.


SCJP 1.4 91%, SCJP 1.5 88%, SCJD B&S
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: too much text in textpane
 
Similar Threads
displaying html in JTextPane of JDK 1.1.8
HTMLEditorKIT
how to append text of one JTextPane to another JTextPane across the network.
Need help in saving the diff colored text in JTextPane in diff format
Retrieving formatted text from mysql database