Search code examples
pluginsawtimagej

ImageJ: how to get Image inside GenericDialog to repaint?


In my ImageJ plugin I display a GenericDialog which has a bunch of images attached to it, like this:

// global:
ColorProcessor cp = new ColorProcessor(50, 50); // new ColorProcessor
ImagePlus ip;

public void run(ImageProcessor ip) {
  GenericDialog gdiag = new GenericDialog("Foo"); // new Dialolg

  gdiag.addDialogListener(this); // adding Listener
  gdiag.addMessage("Lorem Ipsum"); // adding Message
  gdiag.addSlider("Bar", 1, 360, 1); // adding Slider

  Color c = new Color(r, g, b);
  cp.setColor(tarColor);
  cp.fill();
  ip = new ImagePlus("fooimg", cp);

  gdiag.addImage(ip);
  gdiag.showDialog();
}

I keep a reference to the Colorprocessor and the ImagePlus. When the slider gets moved on the GenericDialog, my the dialogItemChanged() event fires. Here I change the Color on the Image:

public boolean dialogItemChanged(GenericDialog gd, AWTEvent event) {
  float fooVal = (float) ((Scrollbar)(gd.getSliders().get(0))).getValue();

  // calculating color based on fooVal ...

  Color selColor = new Color(r, g, b);
  cp.setColor(selColor);
  cp.fill();
}

Now when I run this, the Color in the Image does not update. Only when I change the size of the dialog and move the border over the image, the color displays correctly.

How can I force the dialog to repaint?

I tried so many different updates & repaints, I am out of options.


Solution

  • Wayne Rasband added this capability in the 1.51b12 daily build of ImageJ; see his response on the ImageJ mailing list, where this question was cross-posted.