0
我有一個問題。我在一個JTextPane chatWindow中追加了一個帶有insertString的字符串,但唯一的問題是我不知道如何'insertString'到我的JTextPane。這裏是我的代碼:將字符串附加到JTextPane中
private void showMessage(final String string){
SwingUtilities.invokeLater(
new Runnable(){
public void run(){
//chatWindow.append(string);
//THE BOTTOM METHOD IS USED FOR APPENDING A STRING JTEXTPANE STYLE
try
{
//doc.insertString(0, "Start of text\n", null);
//doc.insertString(doc.getLength(), "", string);
//doc.insertString(int offset, String str, ArributeSet a);
//SETTING THE STYLE FOR THE STRING (down below)
StyleConstants.setForeground(keyWord, Color.getHSBColor(251, 89, 87));
//StyleConstants.setBackground(keyWord, Color.YELLOW);
StyleConstants.setBold(keyWord, false);
doc.insertString(0, string, keyWord);
}
catch(Exception e) { System.out.println(e); }
}
}
);
}
凡說:
doc.insertString(0, string, keyword);
這是我在我的追加字符串到chatWindow。我唯一的問題是,我不知道如何「insertString」專門給chatWindow像我在上面的try-catch方法的說明是如何做到:
chatWindow.append(string)
有誰知道我可以用「doc.insertString (0,string,keyword);'將字符串關鍵字插入chatWindow? doc.insertString的結果不會顯示在我的chatWindow上。謝謝。
什麼是doc類型? –
爲了更快得到更好的幫助,請發佈[SSCCE](http://sscce.org/)。 –
我在哪裏發佈此SSCCE? – user2596934