From: Kevin M. <kev...@er...> - 2001-07-23 10:20:45
|
Thanks, your example was very useful. If I call MyThread().run() and I am not in the event-dispatching thread, everything works fine. I can do long tasks and call invokeLater to update the GUI with each result. If I call MyThread().run() when a button is pressed, then isEventDispatchThread() returns true and the updater function is called directly. This is because button events are handled in the event-dispatching thread, but the result is that the GUI is not updated until the button event finishes :( What I am doing wrong? /Kevin On Thu, 19 Jul 2001, D-Man wrote: > On Thu, Jul 19, 2001 at 03:57:38PM +0200, Kevin McNamee wrote: > | > | I am trying to use threads so that I can revalidate some panes while > | performing a series of long tasks, i.e. > | > | long task > | update & revalidate pane > | long task > | update & revalidate pane > | etc. > > Ok. You have this loop in a thread (some subclass of > java.lang.Thread). When you want to update the GUI you update it via > the SwingUtilities class. Ex : > > class MyThread( java.lang.Thread ) : > def run( self ) : > for ... : > ... > > # now update the GUI, create an java.lang.Runnable that > # does the work > class updater( java.lang.Runnable ) : > def run( self ) : > <update the gui here> > > if javax.swing.SwingUtilities.isEventDispatchThread() : > # we are already in the AWT_EventQueue thread, it is > # safe to touch the GUI > updater().run() > else : > # request that the updater be run in the > # AWT_EventQueue thread > javax.swing.SwingUtilities.invokeLater( updater() ) > > > > HTH, > -D > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users > _________________________________________________ Name/Title : Kevin McNamee, Software Consultant Phone : +46 13 32 1165 E-Mail : kev...@er... |