named label options
The options.addLabel function doesn't allow me to specify a name for the label. I would like to be able to programatically modify labels and retrieve their values, for example, using options.getValueAsString.
I see that there is a constructor where I can make a new label with a specified name:
Options.LabelOption(String name, String label)
But I can't figure out how to add that to the menu layout.
Is "addCustomOption" the right way to do that? I feel like since a label is not a custom option, maybe there is a more preferred way.
-
It is a bit weird but I recommend the following:
Option labelOption = addCustomComponent(new JLabel("hello world"));
You can then use labelOption.getComponent() to get your JLabel.
0 -
Thanks for the response. I'm not sure that works for me though.
I specifically want to give labels names and be able to retrieve them using options.getValueAsString
This is because I want to be able to set their value in the getOptions method and get it back in the performOperation method. As far as I know the only way to pass information between those two methods is through the "options" variable returned by getOptions.
As a last resort I was thinking of making shadow string options to track the label values, for example using something like:
options.addStringOption("Label_1_value", "",labelOption.getValue()).setHidden(true);
But that seems clunky and I'd like to avoid it if possible.
0 -
Right, in that case I think you can use:
addCustomOption(new LabelOption("name", "label"));
then getValueAsString("name") should work to retrieve "label".
0
Please sign in to leave a comment.
Comments
3 comments