Java TextComponent Document real time updating

28 views Asked by At

I am writing a simple UI debug console to be used for my software, games, etc. Currently it prints out the lines in bulk. By which I mean if I were to make a for loop counting to 5000 and print a line each time, it would count to some number, say 500, then pause, jump to 1500, pause, jump to 3000, etc. I'd like to make it act more like consoles in IDEs do, printing out the lines in real time. How can I achieve this?

    public void print(String line) {
    try {
        int offset = document.getLength();
        document.insertString(offset, line + "\n", attributes);
        textComponent.setCaretPosition(offset);
    } catch (BadLocationException e) {
        //e.printStackTrace();
    }
}

document ends up set as textComponent.getDocument() I am using a document because I have normal output and error output being shown as different colors.

0

There are 0 answers