Applying setLocation to different types of dialogs

Hi there,
I have been trying to avoid overlapping windows when running a macro.
After searching for a bit, it seems that:
setNextLocation can be applied to :

  • Images
  • Waitforuser boxes

setLocation can be applied to

  • Images
  • Dialog box

I was wondering about:

  • showMessage (and showmessagewithcancel)
  • getDirectory (with our without Jfilechooser)
  • File.openDialog

Is it possible to set their location or their Next location?

Not easily. Those are all modal dialog boxes which use the ImageJ main application frame as their parent. IIRC, how the location is chosen is platform-dependent, and in general not configurable.

Some while ago somone with more expierience with FiJi gave me that code.
Its doing some java magic :wink: I used it to place the log window somwhere else.

script =                                                    
    "lw = WindowManager.getFrame('Log');\n"+  //replace "log" with your window name
    "if (lw!=null) {\n"+
    "   lw.setLocation(xpx, ypx);\n"+        //position                        
    "   lw.setSize(xpx, ypx)\n"+              //size                    
  eval("script", script);`

If you dont want to make the position (xpx & ypx) fixed to your screen location you can use variables as well.
You just replace the xpx with the following code " + xvariable + " with the ".

Maybe this is what you are looking for.

Best Tobias

1 Like

@TMC Cool hack. Unfortunately, for modal dialogs, it is more difficult because commands like showMessage create a new window and then block until it closes again, leaving no opportunity within the macro to control the window placement—at least not without some serious voodoo. (E.g., you could eval a script that spawns a new polling thread, for example… yuck…)

@nstifani Do you really need this fine-grained level of control over these dialogs? Is it worth the pain?

@ctrueden “really” :wink: not really. We could drill down the philosophical meaning of really. Aside of the theoretical question, fine control over window management could be nice. If not easily addressable, it won’t be the end of the world (at least my world).
@TMC :
It is always a ratio benefits/costs. To my understanding in this specific case the benefits are medium and the costs (energy and time) high.

Anyhow, Thank you guys for proposing, suggesting. I wish I could find community as nice as this in my specific scientific field.