1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public void add(String text, boolean format) {
DefaultStyledDocument doc = (DefaultStyledDocument) this.console.getDocument();
SimpleAttributeSet attr = new SimpleAttributeSet();
if (!format)
attr.addAttribute(StyleConstants.Foreground, Color.RED);
else
attr.addAttribute(StyleConstants.Foreground, Color.BLACK);
int len = this.console.getText().length();
int offs = (len-1<0) ? 0 : len-1;
try {
doc.insertString(offs, "> " + text + "\n", attr);
} catch (BadLocationException e) {
e.printStackTrace();
}
} |