HTML tables in JTextPane showing weird "form" boxes

Posted by Ted on Stack Overflow See other posts from Stack Overflow or by Ted
Published on 2012-11-09T22:57:41Z Indexed on 2012/11/09 22:59 UTC
Read the original article Hit count: 248

Filed under:
|
|
|
|
            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!

Thanks yall!

© Stack Overflow or respective owner

Related posts about java

Related posts about html