Example usage for javax.swing.text StyledDocument setLogicalStyle

List of usage examples for javax.swing.text StyledDocument setLogicalStyle

Introduction

In this page you can find the example usage for javax.swing.text StyledDocument setLogicalStyle.

Prototype

public void setLogicalStyle(int pos, Style s);

Source Link

Document

Sets the logical style to use for the paragraph at the given position.

Usage

From source file:homenetapp.HomeNetAppGui.java

private void updateTextPane(final String text, final javax.swing.text.Style color) {
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            javax.swing.text.StyledDocument doc = consoleTextPane.getStyledDocument();

            try {

                // consoleTextPane.se
                if (color != null) {
                    doc.setLogicalStyle(doc.getLength(), color);
                }/*from w w  w  .  ja  va  2  s  .  co  m*/
                doc.insertString(doc.getLength(), text, null);

                if (doc.getLength() > 10000) {
                    doc.remove(0, text.length());
                }
            } catch (javax.swing.text.BadLocationException e) {
                throw new RuntimeException(e);
            }
            consoleTextPane.setCaretPosition(doc.getLength() - 1);
        }
    });
}