Widget default attribute

I starting doing a bit of ImageJ2 coding in Java :stuck_out_tongue:
I came across the Widgets, which seems to be the same or (almost) than the script parameters.

I was surprised that there is min and max attributes but no default value attribute.
I found out the initializer field which seems to be the closest match to what I am looking for.

So I just have to set this initializer field to a function that returns the default value as a string for that parameter, right ?

1 Like

I would rather turn it around: script parameters are an extension of the Java @Parameter notation in SciJava to script languages. The @ annotations are a feature of the Java programming language, and the org.scijava.plugin.Parameter class makes add a custom annotation to this feature.

And widgets, in turn, are UI elements that โ€“ when present โ€“ allow to harvest parameter input from the user via the UI. But theyโ€™re not required: you can use parameters without widgets, e.g. when they are auto-fillable (such as SciJava Services), or when you provide the input in another way (such as via command line, or by handing them over in your call to ScriptService). Widgets are implemented in the UI to simplify parameter input, but parameters in general are UI-independent and work headless.

Oh, no, you donโ€™t need to be complicated. An initializer is useful for dynamic initialization, if the value depends on another value only known at runtime.

If you just want to set a default value, you can assign a value to the annotated variable in your Java code:

@Parameter (label = "Please enter your name")
private String name = "myDefaultName";
1 Like

Perfect thanks ! Iโ€™m quite excited by this new world of possibilities :smiley:

1 Like