是否可以将HTML加载到jTable中?

时间:2014-04-02 11:45:56

标签: java html swing jtable jframe

是否可以将HTML加载到Java组件中?例如,如果我有HTML - 也许是一个表格(用单元格颜色格式化 - 我可以将它加载到jTable中吗?

1 个答案:

答案 0 :(得分:3)

JTables不像HTML表那样灵活。单元格不能跨越多行或多列。

而不是这个,您可以使用JTextPane并使用HTMLEditor。

您需要将内容tpye设置为text / html并将其设置为false。

JTextPane textPane = new JTextPane();
textPane.setContentType( "text/html" );
textPane.setEditable(false);

之后使用HTML编辑器并继续HTML:

HTMLDocument document = (HTMLDocument)textPane.getDocument();
HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
String text = "your HTML here";
editorKit.insertHTML(document, document.getLength(), text, 0, 0, null);

请注意,这是示例。你必须根据自己的需要进行调整。 我认为这有帮助。