2013-07-21 1 views
0

질문이 있습니다. JTextPane, chatWindow, insertString, 함께 문자열을 추가 오전 유일한 문제는 내 JTextPane 'insertString'방법을 모른다.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 :

chatWindow.append(string) 

사람은 알고 있나요 내가 'doc.insertString을 사용할 수 있습니다 (0, 문자열, 키워드); ' chatWindow에 string 키워드를 삽입 하시겠습니까? doc.insertString의 결과가 내 chatWindow에 표시되지 않습니다. 감사.

+0

doc 유형은 무엇입니까? –

+3

더 나은 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. –

+0

이 SSCCE는 어디에 게시합니까? – user2596934

답변

1

어떨까요?

chatWindow.getDocument().insertString(0, string, keyword); 
관련 문제