2012-07-20 18 views
2

很自我解釋,我有一個字符串是HTML,我如何將它繪製到JEditorPane/JTextPane上?如何將HTML字符串讀入JEditorPane/JTextPane?

+2

[你有什麼嘗試?](http://www.whathaveyoutried.com/)我的意思是*除*有效地要求隨機的陌生人在互聯網上爲你做。 – 2012-07-20 23:56:36

+0

谷歌,玫瑰印度,超級用戶,這等等 – Primm 2012-07-21 14:36:44

回答

7

你的意思是這樣的嗎?

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)函數。