Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JScrollBar error



James Rome wrote:

My App in Java 1.5 has a DefaultStyledDocument in a JScrollPane.

I keep adding more text to the Document and removing them when the

Document.length() > 20000.

(And by the way, if you ever do this, the Document saves all the deleted

stuff unless you override methods in GapContent, which I do-- otherwise

you eventually run out of memory.)


But I would like always to set the scroll bar to the bottom of the

Document after entering text. I do this using:

   private void updateLength() {


...

It works if I leave out the jsb.setValue chunk of code. What am I doing

wrong?


The first thing I'd look for is a code path that could call updateLength on a thread other than the Swing thread. Add some code like this to updateLength:

    if (!SwingUtilities.isEventDispatchThread()) {
        System.err.println ("\n***** Not on EDT!");
        Thread.dumpStack();
    }

(this is from memory, I may have some minor goof-ups in the above code, but it should illustrate the point)

If the message appears, then updateLength has been called from another thread, and the stack trace will tell you how you got there.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.