The moose likes Swing / AWT / SWT and the fly likes JEditorPane and contentType Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JEditorPane and contentType" Watch "JEditorPane and contentType" New topic

JEditorPane and contentType

Constantine Mosch

Joined: Jan 20, 2013
Posts: 10
Sorry for my bad English.

My JPanel contains a JEditorPane. I use the JEditorPane as output.
The text of JEditorPane is changed very frequently and sometimes the text is large (more than 5000 lines).
To show text I am using SwingUtilities.invokeLater(Runnable run)

If the contentType of JEditorPane is "text/plain" the text loads faster than "text/html".

Can I insert first the text into the JEditorPane as plain text and then change the contentType?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
You have got the wrong sort of thing in the run() method. You only need to create the GUI in that method; then don’t start any new threads which affect Swing objects.This assumes that all code required to display the GUI can be accessed (albeit indirectly) from the MyGui() constructor.

I had to edit this post twice because I noticed mistakes in it.
Constantine Mosch

Joined: Jan 20, 2013
Posts: 10
@Campbell Ritchie
Thanks for your reply.
I read here
The event dispatch thread, where all event-handling code is executed. Most code that interacts with the Swing framework must also execute on this thread.
Worker threads, also known as background threads, where time-consuming background tasks are executed.

I am novice and I want you to correct my thinking.
So all GUIs update must be done from EDT. That's why I use SwingUtilities.
I dont use SwingWorker because SwingWorker must be used for background long-running tasks.
Here is a SSCCE example. I read a large text file and I show it in a JEditorPane.
How can I increase the speed of insertion in a JEditorPane?

I agree. Here's the link:
subject: JEditorPane and contentType
jQuery in Action, 3rd edition