【发布时间】:2014-07-30 07:08:13
【问题描述】:
我的班级中有一个JEditorPane,我正在尝试向其中添加文本。 (我没有使用文本区域或窗格,因为它必须支持某些内容,例如 HTML)
我遇到的问题是(我的 JEditorPane 称为 chatLog),当我输入 chatLog.setContentType("text/html"); 并输入 chatLog.setText("Test");
什么都没有发生...
第二次我注释掉/删除chatLog.setContentType("text/html");应该出现的文本,看起来很好。
我不知道我做错了什么。
来源:
public ServerGUI() {
// Rest of code above.
JEditorPane chatLog = new JEditorPane();
chatLog.setContentType("text/html");
chatLog.setEditable(false);
// Rest of code below.
}
public void appendText(String str) {
// Can use a word instead of str too like the "Test" above.
chatLog.setText(chatLog.getText() + str);
//chatLog.setCaretPosition(chatLog.getText().length() - 1);
}
此外,我遇到的另一个小问题不是太大,当我将内容类型设置为 HTML 时,我无法将插入符号的位置设置为如上所示。它说有一个IllegalArgument Exception
感谢您的帮助。
【问题讨论】:
-
我认为你有一个 x --> y 问题,从这个问题中看不清楚 - 投票结束的范围太广,(如何以及是否使用 XxxEditorKit,覆盖或初始化),but shot into the dark .... by @Guillaume Polet
-
或者好吧,现在已经解决了,不用担心。
标签: java html swing jeditorpane