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 8832887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:38:37+00:00 2026-06-14T08:38:37+00:00

I’m trying to put an html table in an editable JTextPane. So you can

  • 0

I’m trying to put an html table in an editable JTextPane. So you can edit tables in it like an excel sheet. When I try to do it, these weird col and colgroup boxes keep showing up. Also, the table doesn’t seem to work like they’re supposed to..

Here’s an example:

            import java.awt.BorderLayout;
            import java.awt.EventQueue;
            import javax.swing.JFrame;
            import javax.swing.JPanel;
            import javax.swing.JTextPane;
            import javax.swing.border.EmptyBorder;
            import javax.swing.text.Document;
            import javax.swing.text.html.HTMLEditorKit;
            import javax.swing.text.html.StyleSheet;

            public class htmlEditor2 extends JFrame {
                private JPanel contentPane;
                public static void main(String[] args) {
                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            try {
                                htmlEditor2 frame = new htmlEditor2();
                                frame.setVisible(true);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }
                public htmlEditor2() {
                    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    setBounds(100, 100, 450, 300);
                    contentPane = new JPanel();
                    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                    contentPane.setLayout(new BorderLayout(0, 0));
                    setContentPane(contentPane);
                    Foo f = new Foo();
                    f.setText("<html><body><table border=\"1\" width=\"985\" cellpadding=\"3\" cellspacing=\"0\" style=\"table-layout: fixed; border-collapse: collapse; border-width: 0px; border-color: #010101; \"><colgroup><col width=\"328\"></col>        <col width=\"328\"></col>        <col width=\"328\"></col>    </colgroup><tr><td align=\"left\" valign=\"top\" width=\"321\" style=\"border: solid #010101 1px; \"><div align=\"left\"><font face=\"Arial\"><span style=\"font-size:8pt\">row 1</span></font></div></td><td align=\"left\" valign=\"top\" width=\"321\" style=\"border: solid #010101 1px; \"><div align=\"left\"><font face=\"Arial\"><span style=\"font-size:8pt\">row2</span></font></div></td><td align=\"left\" valign=\"top\" width=\"321\" style=\"border: solid #010101 1px; \"><div align=\"left\"><font face=\"Arial\"><span style=\"font-size:8pt\">row3</span></font></div></td></tr><tr><td align=\"left\" valign=\"top\" width=\"321\" style=\"border: solid #010101 1px; \"><div align=\"left\"><span style=\"font-size: 8pt;\">&nbsp;</span></div></td><td align=\"left\" valign=\"top\" width=\"321\" style=\"border: solid #010101 1px; \"><div align=\"left\"><span style=\"font-size: 8pt;\">&nbsp;</span></div></td><td align=\"left\" valign=\"top\" width=\"321\" style=\"border: solid #010101 1px; \"><div align=\"left\"><span style=\"font-size: 8pt;\">&nbsp;</span></div></td></tr><tr><td align=\"left\" valign=\"top\" width=\"321\" style=\"border: solid #010101 1px; \"><div align=\"left\"><span style=\"font-size: 8pt;\">&nbsp;</span></div></td><td align=\"left\" valign=\"top\" width=\"321\" style=\"border: solid #010101 1px; \"><div align=\"left\"><span style=\"font-size: 8pt;\">&nbsp;</span></div></td><td align=\"left\" valign=\"top\" width=\"321\" style=\"border: solid #010101 1px; \"><div align=\"left\"><span style=\"font-size: 8pt;\">&nbsp;</span></div></td></tr></table><div align=\"left\">&nbsp;&nbsp;</div></body></html>");
                    contentPane.add(f);
                }
                class Foo extends JTextPane {
                    public Foo() {
                        super();
                        HTMLEditorKit kit = new HTMLEditorKit();
                        setEditorKit(kit);
                        StyleSheet styleSheet = kit.getStyleSheet();
                        styleSheet.addRule(""); //in case I need to add a CSS
                        Document doc = kit.createDefaultDocument();
                        setDocument(doc);
                    }
                }
            }

I would paste a nicely formatted version of the html, but I’m not sure how to do it on here…

So yeah.. I just want to know how to get rid of those weird colgroup and col boxes in my table and how to make the table work normally!

UPDATE: So it turns out that the service that I’m retrieving the html tables from autoformats the html table to include the <colgroup> and <col> tags. So I have some follow up questions: Does JTextPane support current html versions? And of course, How do I get the JTextPane to not display those weird boxes?

  • 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-06-14T08:38:38+00:00Added an answer on June 14, 2026 at 8:38 am

    My solution was to just use a String.replaceAll() and removed everything I didn’t want. I know it seems weird.. buuut. for now. That’s my solution. Thanks Reimeus for your answer. I will have to look into your solution when I have a chance.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.