我想解決與安裝HTMLEditorKit時使用JEditorPane.getText()不一致。JEditorPane與HTMLEditorKit返回換行符而不是<br>標記
我可以使用JEditorPane.setText傳遞包含< br>標籤的HTML字符串,並且當我使用getText()時,這些新行將正確顯示爲< br>。但是當用戶在JEditorPane中輸入新行時,getText()會返回一個「/ n」字符而不是標籤。我的自定義HTML解析器無法區分用戶的「/ n」字符和添加的「/ n」字符 - 看起來 - 使HTML字符串看起來很漂亮。舉個例子:
如果用戶輸入一些文字,在JEditorPane.getText()過程將返回這樣的事情:
<html>
<head>
</head>
<body>
I've written some text! Indeed so much text that this line is probably
going to word wrap when I run the getText procedure!
And now I just hit enter a few times! I wonder what will happen if it wraps
another time? WHAM.
And I'll hit enter once more for good measure.
</body>
</html>
雖然我預計這顯示爲:
<html>
<head>
</head>
<body>
I've written some text! Indeed so much text that this line is probably
going to word wrap when I run the getText procedure!<br><br>And now I
just hit enter a few times! I wonder what will happen if it wraps
another time? WHAM.<br>And I'll hit enter once more for good measure.
</body>
</html>
當用戶輸入時,是否有任何方法可以將<插入到getText字符串中?我第一次嘗試使用documentFilter,但文檔說我只是大聲地在過濾器中使用insertString或filterBypass,因此我不能使用setText(「< br>」)路由。大量的閱讀後,我想另一種選擇是擴展HTMLEditorKit並重寫讀取過程? JTextComponents對我來說是新的,所以這是我的頭。還有其他選擇嗎?或資源?
謝謝!
您是否曾經發布SSCCE來說明問題? – StanislavL 2014-11-10 09:26:32