Repaint Image inside GenericDialog

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Repaint Image inside GenericDialog

Alex_Doe
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.
Reply | Threaded
Open this post in threaded view
|

Re: Repaint Image inside GenericDialog

ctrueden
Hi Alex,

I see that you cross-posted this on StackOverflow at:
http://stackoverflow.com/q/37360832/1207769

I commented there with a couple of quick questions/ideas.

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - http://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - http://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Sat, May 21, 2016 at 4:32 AM, Alex_Doe <[hidden email]> wrote:

> 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.
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Repaint-Image-inside-GenericDialog-tp5016483.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Repaint Image inside GenericDialog

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Alex_Doe
> On May 21, 2016, at 5:32 AM, Alex_Doe <[hidden email]> wrote:
>
> In my ImageJ plugin I display a GenericDialog which has a bunch of images
> attached to it, like this:

Upgrade to the latest ImageJ daily build (1.51b12) and add gd.repaint() to the dialogItemChanged() method. The following JavaScript example, which updates an image in a GenericDialog, works with the daily build but not with earlier versions of ImageJ.

-wayne

    img = IJ.openImage("http://imagej.nih.gov/ij/images/clown.jpg");
    ip = img.getProcessor();
    ip.snapshot();
    listener = new DialogListener {
        dialogItemChanged : function(gd, event) {
            gamma = gd.getNextNumber();
            ip.reset();
            ip.gamma(gamma);
            img.setProcessor(ip);
            gd.repaint();
            return true;
        }
    };
    gd = new GenericDialog("Gamma Adjuster");
    gd.addImage(img);
    gd.addSlider("Gamma:", 0.05, 5.0, 1);
    gd.addDialogListener(listener);
    gd.showDialog();


> /// 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.
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Repaint-Image-inside-GenericDialog-tp5016483.html
> Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html