tags:

views:

313

answers:

2

I occasionally get an exception in a JTextArea that I'm updating with JTextArea.append() ...

java.lang.IllegalArgumentException: Invalid remove
    at javax.swing.JTextArea.replaceRange(Unknown Source)
    at sun.plugin.ConsoleWindow$24.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

Is there anything that I could be doing wrong that's causing this exception? The javadoc suggests that the method should be thread-safe.

+2  A: 

Document does not provide a rich enough interface to be usefully used in a thread-safe manner. JTextArea will have some thread-safety claims removed in JDK7. Stick to updating Swing components and Swing text objects in the AWT Event Dispatch Thread (EDT).

Tom Hawtin - tackline
+1  A: 

Check out this for a very useful tool for checking thread abuse in Swing: http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing.html

TofuBeer