Mailing Lists: Apple Mailing Lists

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

Forcing a Swing GUI update - problem resolved



Many thanks to all who responded to my original post about some very active electronic display simulators blocking the update of a Swing based control panel. If you recall, the electronic displays simulate things like spectrum analyzers, o-scopes, etc. and when three or more of them were opened up (these are VERY active drawing programs) the Swing control panel that would send them parameters to change things (like center frequency, bandwidth, timing) would really be blocked and it would look like a couple of gray rectangles (eventually it would fill in, but end up in the same state if another window covered the Swing stuff).

In any case, an analyisis of the code showed that ALL of the work for updating the electronic display simulators was done in the paint() method. In p-code this would look like this:

1. Obtain data to be graphed from source.
2. Initialize graphics, etc.
3. Load into buffer
4. Analyze timing and scale diagram properly, set sleep value for "run()" here
5. Draw image


paint() is of course triggered by re-paint and this is issued by a main-thread in a run() method, which when simplified is little more than:

sleep(<time calculated from step 4>)
repaint();

The code in steps 1-4 above is a TON of code. It was ALL running on the event dispatching thread.

The problem was resolved by cutting a lot of code out of the paint() method, putting it in a new method called inside the run() method which is running in a main-thread, NOT the event dispatching thread, and once the image is prepared, draw it inside the paint() method (on the event dispatching thread).

Now the p-code looks like this

paint():
1. Draw image

newMethod():
1. Obtain data to be graphed from source.
2. Initialize graphics, etc.
3. Load into buffer
4. Analyze timing and scale diagram properly, set sleep value for "run()" here


run() (looping of course)
1. call newMethod() to do all the heavy work
2. sleep allocated time from newMethod()
3. repaint().

Needless to say, a wait/notify set had to be introduced.

NOW IT WORKS FINE!!!

Thanks everyone.

P.S. : For any of you future book writers out there please STRESS the importance of the event dispatching thread and its effect on graphics updates.


_______________________________________________ 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.