JTextPane appending a new string

后端 未结 3 964
难免孤独
难免孤独 2020-11-27 04:40

In an every article the answer to a question \"How to append a string to a JEditorPane?\" is something like

jep.setText(jep.getText + \"new string\");
         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 05:11

    setText is to set all text in a textpane. Use the StyledDocument interface to append, remove, ans so on text.

    txtPane.getStyledDocument().insertString(
      offsetWhereYouWant, "text you want", attributesYouHope);
    

提交回复
热议问题