Can the ImageJ2 @Parameter input harvester automatically generate a set of radio buttons?

Tags: #<Tag:0x00007fd6a1999330> #<Tag:0x00007fd6a1998ed0> #<Tag:0x00007fd6a1998a70>


I’m new to ImageJ2 command plugins, and I see that the input
harvester framework can automatically generate a gui to get
parameter values from the user. Is there some way to use the
@Parameter annotation (or some other way) to have a set of
radio buttons automatically generated?

Thanks, mm


You can influence the appearance of the generated dialog components using the style property of the @Parameter annotation:

shows some examples, all possibilities for choices can be seen here:


Gabriel, thank you.

This worked for me in my IJ2-style plugin java code:

@Parameter(label = "String parameter", choices = {"aaa", "bbb", "ccc"}, style = "radioButtonVertical")
private String stringParameter;

And, sure enough, I get radio buttons for my choices.

Unfortunately, my initial (randomly chosen, experimental) test use case was for an int parameter. I can’t get choices to work with that.

This seems to be contrary to the documentation. From (that you quote):

As with ImageJ2 plugins, script parameterization is based on the SciJava @Parameter annotation—so experience with plugin writing directly translates to scripting, and vice versa.

So I assume that this documentation should be relevant to my java code.


Any parameter can be turned into a multiple-choice selector by adding a choices = {…} property:

I read that as “any type of parameter,” but in my experiments, it doesn’t work with int (or Integer) parameters, at least not in java, and at least not for me.

Code snippet:

@Parameter(label = "int parameter")                            // works, but no choices feature

// error: incompatible types: int cannot be converted to String
// @Parameter(label = "int parameter", choices = {1, 9})       // fails at compile time

// java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
// @Parameter(label = "int parameter", choices = {"1", "9"})   // fails at run time

private int intParameter;                                     // Integer has same problems as int

It’s not particularly important for what I’m doing, but I would be
curious as to whether I should expect choices (and radio buttons)
to work for other than String parameters.

Thanks, mm


I looked into the code, choices only works with Strings, you could always use e.g. Integer.parse(..) to turn the String into a number. The underlying assumption is that you provide a choice between categorical values.

If you want to create a number input with a limited range you can use the following code:

@Parameter(style="slider", min=0, max=100, stepSize=10)
private int integerRangeBound;


Thank you for your follow-up Gabriel.

Yes, I noticed the code after I posted – the choices feature is, indeed,
only implemented for String Parameters.

I’m only playing around right now, so it’s not an issue – I was just
trying understand why something I thought should be possilbe
wasn’t working.

Thanks, mm