如何将HTML字符串读入JEditorPane/JTextPane?

5
相当明显,我有一个HTML字符串,我该如何将其绘制到JEditorPane/JTextPane上?

2
你尝试过什么?我的意思是,除了在互联网上有效地向陌生人请求帮助之外。What have you tried? - Andrew Thompson
谷歌、Rose India、超级用户、这个等等。 - Primm
2个回答

15

你的意思是这样吗?

JFrame frame=new JFrame();
JEditorPane pane=new JEditorPane();
pane.setContentType("text/html");
String data="<table border=\"1\"><tr><td>cell1</td><td>cell2</td></tr></table>";
pane.setText(data);

frame.add(pane);
frame.setSize(200,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

0

如果您想将单个字符串放入窗格中,需要找到一个HTML解释器。但是,如果您处理的是包含HTML的单独页面,您可以使用JTextPanesetPage(String URL)函数。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接