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

  • SEARCH
  • Home
  • 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 3997786
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:26:40+00:00 2026-05-20T07:26:40+00:00

I have a question regarding some simple console I’m making. I know that it’s

  • 0

I have a question regarding some simple console I’m making. I know that it’s possible to add html content to JTextPane with function setText() with previously set setContentType("text/html"); . But for the needs of my application I need to work directly with javax.swing.text.Document, which I get with getDocument() function(for example for removing the lines and appending the new ones, yes it’s kind of console I’m making and I have already seen several examples in previous StackOverflow questions, but none of them serves my needs). So, what I want is insert the HTML to the document and have it correctly rendered on my JTextPane. The problem is when I add HTML content with insertString() method(which belongs to the document), JTextPane is not rendering it, and in output I see all the html tags. Is there any way to get this working correctly?

That’s how I insert the text:

text_panel = new JTextPane();
text_panel.setContentType("text/html");

//...

Document document = text_panel.getDocument();
document.insertString(document.getLength(), line, null);
text_panel.setCaretPosition(document.getLength());
  • 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-20T07:26:41+00:00Added an answer on May 20, 2026 at 7:26 am

    You need to insert using an HTMLEditorKit.

        JTextPane text_panel = new JTextPane();
        HTMLEditorKit kit = new HTMLEditorKit();
        HTMLDocument doc = new HTMLDocument();
        text_panel.setEditorKit(kit);
        text_panel.setDocument(doc);
        kit.insertHTML(doc, doc.getLength(), "<b>hello", 0, 0, HTML.Tag.B);
        kit.insertHTML(doc, doc.getLength(), "<font color='red'><u>world</u></font>", 0, 0, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple question and wish to hear others' experiences regarding which is
I have a simple question regarding best practices in programming. I have a DB
I am new to TDD and DDD and I have one simple question regarding
I have some questions regarding MVC that I would like to clarify. At our
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
I have a question regarding handling errors in a J2EE application. Our current application
I'm writing a small webapp in Grails and I have the following question regarding
Following on from my recent question regarding parsing XML files in Java I have
I have a question about best practices regarding how one should approach storing complex

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.