groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Johnson <>
Subject SwingBuilder question
Date Mon, 14 Sep 2015 11:33:42 GMT
I'm using SwingBuilder in a perhaps overly complex way, and need help to
make things work.  The system is large, but someone else wrote almost all
the SwingBuilder code, and I am far from an expert on SwingBuilder.

My system has a class BackgroundTask that extends SwingWorker and that lets
me write something like

def task = BackgroundTask().taskBody {}.whenDone {}

A BackgroundTask can also be given closures for onStart and onProgress, but
that is probably TMI.  As you might expect, the closures for taskBody and
whenDone run in different threads.

All the closures get processed by a method configBody, which is

private Closure configBody(Closure c) {

   // Set the delegate to be me, and set resolve so I am first

   c.delegate = this

   c.resolveStrategy = Closure.DELEGATE_FIRST

   return c


My guess is that the purpose of this is so that the closures passed to
BackgroundTask can use methods from BackgroundTask without having to
mention it.  BackgroundTask has a getMonitor method and I notice that the
closures often just say "monitor" and expect to access the monitor in the

BackgroundTask was written by someone else a few years ago, gets used a
fair bit, and has not been a problem.  Until now.

I want one of the tasks to pop up a window to display errors when it is
done.  If there are errors.  So, I put something like

def swing = new SwingBuilder()

def frame = swing.edt {

         frame(...) { ... }


at the end of the whenDone closure, and I get the error "No signature of
method BackgroundTask.frame is applicable for ..."   This seems very weird
to me.   I would have thought that frame() would have been handled by
SwingBuilder, not BackgroundTask.   I am thinking that configBody has
hacked the closures so they don't work, except that the closures it hacks
are the ones that contain the SwingBuilder, not the ones that the
SwingBuilder handles.  Based on what I know about Groovy, I would have
expected SwingBuilder to continue to work inside these closures.

I tried moving the code that pops up the window.  It can be in the taskBody
closure or the whenDone closure.   It can use the edt method of
SwingBuilder or the frame method.  No matter what I do, I get the same kind
of error.

Any suggestions would be appreciated!

-Ralph Johnson

View raw message