Terai Atsuhiro 2021-12-24 (金) 12:38:13

http://terai.xrea.jp/swing/styleconstants/screenshot.png

private void append(final String str, final boolean flg) {
  SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      SimpleAttributeSet sas = null;
      if(!flg) {
        //sas = new SimpleAttributeSet(jtp.getCharacterAttributes());
        sas = new SimpleAttributeSet();
        StyleConstants.setForeground(sas, Color.RED);
        //StyleConstants.setBold(sas, true);
        //StyleConstants.setFontFamily(sas, "Monospaced");
        //StyleConstants.setFontSize(sas, 32);
        //StyleConstants.setForeground(sas, Color.GREEN);
      }
      try{
        Document doc = jtp.getDocument();
        doc.insertString(doc.getLength(), str+"\n", sas);
        jtp.setCaretPosition(doc.getLength());
      }catch(BadLocationException e) {}
    }
  });
}