It seemed that the question is asking how to display a list of selected strings. It seemed quite possible that underlying that, is how to pick variables in the same way, which takes a little more care. (You can substitute inside the Dynamic[resultingList = ...]
the expression {a, b, c}
or varList
for labelList
, if you want the list to be the variables.)
labelList = {"a", "b", "c"};
varList := {a, b, c};
CheckboxBar
You can use CheckboxBar
, but the check boxes have to appear together.
x = {};
{CheckboxBar[Dynamic[x], {1 -> "a", 2 -> "b", 3 -> "c"}],
Dynamic[resultingList = labelList[[Sort@x]]]}

Checkbox
If you want to place the check boxes wherever, then you can use Part
s of a List
.
y = ConstantArray[False, 3];
{"a:" Checkbox[Dynamic[y[[1]]]], "b:" Checkbox[Dynamic[y[[2]]]],
"c:" Checkbox[Dynamic[y[[3]]]], Dynamic[resultingList = Pick[labelList, y]]}
More succinctly, and with Row
to format the label-check-box pairs:
pickedVars = ConstantArray[False, 3];
{MapIndexed[Row[{#1, Checkbox[Dynamic[pickedVars[[First[#2]]]]]}] &,
{"a: ", "b: ", "c: "}],
Dynamic[resultingList = Pick[labelList, pickedVars]]}

Technically in your original code you're using Times
to format them. It seems to work because the order that Mathematica puts the factors in happens to be the one you desire. You can also use Labeled
instead of Row
, as well as several other commands.
You can also wrap the whole thing with Row
and get rid of the List
braces (modifying the list structure a little first).
TogglerBar
In case you're open to alternatives, TogglerBar
could be used instead, but you may already know that.
z = {};
{TogglerBar[Dynamic[z], labelList], Dynamic[resultingList = Sort@z]}

To get the variables, you can use the following:
z2 = {};
{TogglerBar[Dynamic[z2], {1 -> "a", 2 -> "b", 3 -> "c"}],
Dynamic[resultingList = varList[[Sort@z2]]]}