Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6849981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:04:04+00:00 2026-05-27T01:04:04+00:00

I have a JEditorPane that displays HTML that is generated programmatically (at runtime). Up

  • 0

I have a JEditorPane that displays HTML that is generated programmatically (at runtime).
Up to now when I was adding a “line” I was re-creating the whole HTML text in a string buffer and then passing it to JEditorPane.setText method.

Now the HTML created has become quite large (can reach up to a few MB) and I would simply add my new line at the end instead of re-generating all the HTML text.

The reason I try to append at the end is to avoid Swing (or the kit ?) having to render/parse the whole text again. Because even though the HTML generation is not performed in the EDT but in another swingworker thread, the “rendering” takes ages. Or the best would be to have a progress bar displaying the progression of the rendering, which is not possible (is it ?).

So my idea is to simply append at the end, but if you have a better idea, it is welcome !

As my text is formatted in an HTML table, I would like to append my new text at the end of this table. For this I tried to use the insertBeforeEnd of the HTMLDocument but I don’t manage to have it working even though I tried plenty of solutions. Notice that I have only “table” tag.

Here is some part of my code

JEditorPane jep = new JEditorPane();
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();

jep.setEditorKit(kit);
jep.setDocument(doc);

//setting dummy text within a HTML table
jep.setText("<table><tr><td>A line of text</td></tr><tr><td>Another line of text</td></tr></table>");

Now for appening some text at the end of this table

//getting the Table Element
Element e = doc.getElement(doc.getDefaultRootElement(), StyleConstants.NameAttribute, HTML.Tag.TABLE);

Note that the element seems to be found correctly as System.out.println(e.getName()) gives “table”

Now

//inserting text at the end of the table
try {
        doc.insertBeforeEnd(e, "<tr><td>A New Line</td></tr>");
    } catch (BadLocationException ex) {
        System.out.println(ex);
    } catch (IOException ex) {
        System.out.println(ex);
    }

Raises me an exception:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: No HTMLEditorKit.Parser
at javax.swing.text.html.HTMLDocument.verifyParser(HTMLDocument.java:1500)
at javax.swing.text.html.HTMLDocument.insertBeforeEnd(HTMLDocument.java:1248)
...

EDIT

I’ve started a new question on the follow up of this one, here is the link :

https://stackoverflow.com/questions/9659209/jeditorpane-htmldocument-different-rendering-how-why

Even though everyhting is working fine with the answer of @JoopEggen the font rendering is not the same and I don’t understand why. As it seems to me a different problem that the one posted here I asked it in another question (the link given above). But it is in my case somewhat of a follow up of this one.

As some may face up the same problem I set this EDIT to point you to the corresponding thread.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:04:04+00:00Added an answer on May 27, 2026 at 1:04 am
    private HTMLDocument doc;
    ...
    JTextPane jep = jTextPane1;
    jep.setContentType("text/html");
    jep.setText("<html><table><tr><td>A line of text</td></tr><tr><td>Another line of text</td></tr></table>");
    doc = (HTMLDocument)jep.getStyledDocument();
    

    The content type followed by a setText installs the EditorKit and determines the document. For that reason take the StyledDocument afterwards. The setText(“…”) again ensures that HTML is taken. (You could have a JLabel or JButton with “< html >< b >H< /b >< i >ello< /i >< span style=’color: #0ff078′ >!!!< /span >”.

    JTextPane is more high level as JEditorPane (strange naming). It provides StyledDocument by which you could do more.

    The rest is okay.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JeditorPane which has some text in HTML format. When I execute
I have a swing client that renders HTML through the use of the JEditorPane
I am creating a Swing application with a JEditorPane that should display an HTML
I have a JEditorPane created by this way: JEditorPane pane = new JEditorPane(text/html, <font
I have a jEditorPane that is HTML based. i found out that you can
I have few links displayed in JEditorPane ex: http://www.google.com/finance?q=NYSE:C http://www.google.com/finance?q=NASDAQ:MSFT I want that I
I am displaying text in a Java JEditorPane using HTML to fomrat the text.
I have an JEditorPane where in some HTML documents are loaded. I want to
I have a small (500kb) swing applet that displays very simple/limited set of small
I have the following tag included in my HTML which causes the JEditorPane not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.