I have an AbstractDocument in a JTextArea in a JScrollPane. I’m writing to the AbstractDocument from a thread that watches a log file – basically doing the equivalent of a “tail -f”. So far, so good.
Here’s the part that isn’t my favourite thing in the world: If I want the JScrollPane to automatically scroll to the bottom of the file when I write to it, I have to do my AbstractDocument.insertText in the event queue thread (using SwingUtilities.invokeLater), but if I don’t want it to scroll to the bottom, I have to do the insertString in a different thread. Is this fucking stupid, or what? Wouldn’t you expect “Scroll to the bottom on input” to be a property somewhere?
So I’ve got a flag for whether I want it to scroll to the bottom or not, and when it’s true, I use SwingUtilities.invokeLater and when it’s false I call insertString directly.
According to the Java bug parade, people want this property, but even when it’s available, they want the current behaviour to remain the default because so many of us have had to write code this way.