当我用 HTML 格式的字符串集中一个字符串,并使用 HTMLEditor 工具包将字符串输出到 JTextPane 时,HTML 标记中包含的每个附加字符串似乎都会导致一个新行:
// Set the HTML Editor kit for JTExtPAne
jtextPane.setEditorKit(new HTMLEditorKit());
String saveCurrentSentenceState = "Some String";
String newWord = "new word"; // wrap this in HTML tags
// Create a HTML String
String appendHTML = "<html><font color=\"red\">"+newWord+"<</font>";
// Concatenate with an existing String
saveCurrentSentenceState += " " + appendHTML;
jtextPane.setText(appendHTML);
JTextPane 中的输出包含不需要的换行符,其中每个 HTML 字符串已连接:
预期的输出将是一行中的所有单词:
你好 gello 顶顶 你好
这是打印到控制台的字符串:
hello gello <html><font color="red">top<</font> <html><font color="red">top<</font> hello
我尝试修剪字符串但输出相同:
saveCurrentSentenceState.trim();
当我在字符串中附加一个 HTML 格式的子字符串时,我不会关闭 HTML 标记,因为在关闭的 HTML 标记之后的任何连接字符串都不会打印。
无论如何我可以停止这个换行表单打印吗?