Posted by
Stein Rørvik on
Apr 17, 2019; 7:11pm
URL: http://imagej.273.s1.nabble.com/Problem-with-using-Radio-Buttons-in-a-plugin-when-called-from-a-macro-tp5022095p5022097.html
Thanks, that works!
But why the difference between running from the GUI and a macro?
The comparison mycar=="Ford" works when the plugin is called via the GUI.
Stein
-----Original Message-----
From: ImageJ Interest Group <
[hidden email]> On Behalf Of Wayne Rasband
Sent: 17. april 2019 20:32
To:
[hidden email]
Subject: Re: Problem with using Radio Buttons in a plugin when called from a macro
> On Apr 17, 2019, at 1:01 PM, Stein Rørvik <
[hidden email]> wrote:
>
> Hello,
>
> I see some strange behaviour with the use of Radio Buttons in plugins.
> The plugins behave correctly when called from the GUI, but not when called from a macro.
You have to use equals() to compare strings in Java. For example, use mycar.equals("Ford") instead of mycar=="Ford".
-wayne
> My plugin is a PlugInFilter, but the exact problem can be reproduced by the simple PlugIn example below.
>
> The macro recorder records this, when selecting button 3:
>
> run("Radio Buttons", "cars=Maserati");
>
> If you run this one-line macro, the first showMessage is shown correctly but not the second one.
> It is not called at all when using a macro. From the GUI it is called correctly.
>
> Does anyone have an idea what is wrong here?
>
> plugin code:
> ----------------------------------------------------------------------------------------
> import ij.IJ;
> import ij.gui.*;
> import ij.plugin.*;
>
> public class Radio_Buttons implements PlugIn {
> String mycar;
> String[] cars = {"Ford", "Citroen", "Maserati", "Volvo"};
>
> public void run(String arg) {
> showDialog();
> IJ.log("Cars: "+ mycar);
> IJ.showMessage("The car you are driving is a " + mycar);
> if (mycar == "Ford") { IJ.showMessage("That is an American car"); }
> if (mycar == "Citroen") { IJ.showMessage("That is a French car"); }
> if (mycar == "Maserati") { IJ.showMessage("That is an Italian car"); }
> if (mycar == "Volvo") { IJ.showMessage("That is a Swedish car"); }
> }
>
> void showDialog() {
> GenericDialog gd = new GenericDialog("Select Car");
> gd.addRadioButtonGroup("Cars", cars, 4, 1, "Ford");
> gd.showDialog();
> mycar = gd.getNextRadioButton();
> }
> }
> ----------------------------------------------------------------------------------------
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html