Posted by
Jon Harman-3 on
Jan 13, 2009; 11:59pm
URL: http://imagej.273.s1.nabble.com/Changing-location-of-a-generic-dialog-tp3694061p3694062.html
Hi,
Thanks for all the help.
I decided to use Curtis' idea. My plugin puts up a dialog again and
again. I want to place the dialog in the same place that the user moved
it before closing it.
Jon
This is what I did: (there must be a more elegant way to initialize the
point)
private static Point gdloc = new Point(-1234,0);
private class PlaceGD implements WindowListener {
private GenericDialog gd;
private Point p;
public void init(GenericDialog gd0, Point p0) {
gd = gd0;
p = p0;
gd.addWindowListener(this);
}
public void windowActivated(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowClosing(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowOpened(WindowEvent e) {
gd.setLocation(p);
}
}
...
GenericDialog gd = new GenericDialog("XXXX");
... setup gd
if(gdloc.x != -1234) pgd.init(gd,gdloc);
gd.showDialog();
if (gd.wasCanceled()) return false;
gdloc = gd.getLocation();
...
Curtis Rueden wrote:
> Hi Wayne & Jon,
>
> Yep, the simple way will work for ImageJ 1.42h, but the dialog will
> remain centered for earlier versions. The most comprehensive solution
> would be to call gd.centerDialog(false) and gd.setLocation(x, y) if the
> version is large enough, and use the ugly WindowListener hack otherwise.
> Not the most elegant, but will always place the dialog correctly, and
> avoid the window flash for 1.42h and above.
>
> -Curtis
>
> On Tue, Jan 13, 2009 at 2:09 PM, Wayne Rasband <
[hidden email]
> <mailto:
[hidden email]>> wrote:
>
> Hi John & Curtis,
>
> Immediately after I posted my message to the list I realized that
> the example could be greatly simplified.
>
> -wayne
>
> import ij.IJ;
> import ij.gui.GenericDialog;
> import ij.plugin.PlugIn;
>
> public class Place_Dialog implements PlugIn {
>
> public void run(String arg) {
> // construct generic dialog
> GenericDialog gd = new GenericDialog("Who Are You?");
> gd.addStringField("Name: ", "", 30);
> if (IJ.getVersion().compareTo("1.42h")>=0)
> gd.centerDialog(false);
> gd.setLocation(100, 100);
> gd.showDialog();
> if (gd.wasCanceled()) return;
>
> // do something trivial with the input
> String name = gd.getNextString();
> if (name == null) name = "";
> name = name.trim();
> if (name.equals("")) IJ.showMessage("Hello!");
> else IJ.showMessage("Hello, " + name + "!");
> }
>
> }
>
>
>