Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

GUI update and threads

Thread view: 
Karsten Wutzke - 30 Mar 2004 23:03 GMT
Hello all!

I use Observer-Observable to update my GUI when desired (setChanged,
notifyObservers). However, I sometimes get an exception irregularly:

java.lang.ArrayIndexOutOfBoundsException: No such child: 4
    at java.awt.Container.getComponent(Container.java:237)
    at javax.swing.JComponent.rectangleIsObscured(JComponent.java:3705)
    at javax.swing.JComponent.paint(JComponent.java:806)
    at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4795)
    at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4748)
    at javax.swing.JComponent._paintImmediately(JComponent.java:4692)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4495)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
    at
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
    at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
    at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

I have three threads running which call methods on objects that lead to
an update of the GUI, so I assume it's a threading problem (due to the
irregularities).

I remember from some time ago, that there was a way to have the AWT
thread handle the repaint (or was it the event dispatcher? or are they
the same?).

Does anyone know how I can post the GUI updates to the "Java GUI repaint
thread"? I can't remember how it was done, I think it was a simple
static method call on some class, but which one?

Can anyone make some other suggestions as to what I could try?

Thanks very much!
Karsten
A. Bolmarcich - 31 Mar 2004 00:08 GMT
> I use Observer-Observable to update my GUI when desired (setChanged,
> notifyObservers). However, I sometimes get an exception irregularly:

[snipped exception tracreback]

> I have three threads running which call methods on objects that lead to
> an update of the GUI, so I assume it's a threading problem (due to the
[quoted text clipped - 7 lines]
> thread"? I can't remember how it was done, I think it was a simple
> static method call on some class, but which one?

Because you are using Swing (the snipped exception traceback included
javax.swing classes), you should use the SwingUtilities.invokeLater(
Runnable) method.  Here is an example from the Java documentation

 Runnable updateAComponent = new Runnable() {
   public void run() { component.doSomething(); }
 };
 SwingUtilities.invokeLater(updateAComponent);

The run() method of the updateAComponent Runnable will be invoked by
the event dispatch thread.
Olivier Chafik - 31 Mar 2004 10:11 GMT
javax.swing.SwingUtilities.invokeLater(Runnable)
javax.swing.SwingUtilities.invokeAndWait(Runnable) throws ...

> Hello all!
>
[quoted text clipped - 11 lines]
> at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
> at

javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQu
> eueUtilities.java:
> 117)
> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
> at

java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
> at

java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
[quoted text clipped - 16 lines]
> Thanks very much!
> Karsten

Signature

°¤oOo¤°livier



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.