GUI update and threads

From: Karsten Wutzke (kwutzke-blahblah_at_emporis.com)
Date: 03/31/04

  • Next message: A. Bolmarcich: "Re: GUI update and threads"
    Date: Wed, 31 Mar 2004 00:03:34 +0200
    
    

    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


  • Next message: A. Bolmarcich: "Re: GUI update and threads"

    Relevant Pages

    • Re: Swing/EDT - Static vs Instance?
      ... I changed the way I write my GUI apps to mimic the example in the Java Tutorial. ... The Tutorial example does the GUI creation in a static method called on the EDT from the main method. ... Why couldn't we just extend JFrame as usual and instantiate it on the EDT? ...
      (comp.lang.java.gui)
    • Re: which thread to create gui
      ... and built the GUI inside the runmethod, then called EventQueue.invokeLater, but I don't think that's the best way to do this. ... and having it just do something simple like calling a static method. ... Scott Delap's ThreadCheckingRepaintManager checks that repaint requests are done from the EDT. Strictly speaking repaint is one of the methods that you should be able to call from another thread. ...
      (comp.lang.java.gui)
    • Swing/EDT - Static vs Instance?
      ... When Sun published the recommendation to create and modify all Swing components in the EDT, I changed the way I write my GUI apps to mimic the example in the Java Tutorial. ... The Tutorial example does the GUI creation in a static method called on the EDT from the main method. ... public static void main{ ...
      (comp.lang.java.gui)
    • Re: GUI update and threads
      ... Karsten Wutzke wrote: ... > an update of the GUI, so I assume it's a threading problem (due to the ... > Does anyone know how I can post the GUI updates to the "Java GUI repaint ... > static method call on some class, ...
      (comp.lang.java.gui)
    • Re: Communication beetween Tk windows
      ... Now I need child to call $pipe->reader; but the problem is that I ... you need the GUI code in each forked process? ... I'd rather have one process driving the GUI and have the childs communicate with that. ... Once MainLoop is running it takes control over your programs flow. ...
      (comp.lang.perl.tk)