Re: Changing location of a generic dialog

Posted by Albert Cardona on
URL: http://imagej.273.s1.nabble.com/Changing-location-of-a-generic-dialog-tp3694061p3694063.html

Jon Harman wrote:
> Hi,
> My plugin uses a generic dialog, but it pops up in an inconvenient
> place.  Is there any way I can change the location?  Maybe somehow
> place it the second time in the same place the user moved it?


Make the class that launches the dialog store the dialog's X,Y position
in the screen. You can get such position by:

GenericDialog gd = ....
Point loc = gd.getLocation();


The ideal position to get such coordinates is in a ComponentListener:

gd.addComponent(new ComponentAdapter() {
    public void componentMoved(ComponentEvent ce) {
        Point loc = ce.getComponent().getLocation();
        // ... store loc somewhere
    }
});


Then, whenever the dialog is opened, set its position (only if any
position recorded):

GenericDialog gd = ....
if (null != loc) {
    gd.setLocation(loc.x, loc.y);
}

The risk above is that the location may be off screen (i.e. if the user
disconnected an extra monitor). You can check that too, using the
GraphicsConfiguration and GraphicsDevice methods.


If the instance of the class that launched the dialog is destroyed, you
can store the "loc" in a static field.

Albert

--
Albert Cardona
http://albert.rierol.net