Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How is the default for the checkboxes created by CheckboxBar in a Manipulate set to be checked instead of unchecked? (The number of checkboxes may be variable.)

share|improve this question
Would you please give an example of the code you are working on? – Mr.Wizard Mar 20 '14 at 15:14
Generally speaking, all controls are set to the initial value(s) of the variables, if any. – Michael E2 Mar 20 '14 at 15:16
up vote 2 down vote accepted

You can specify an initial value to a variable captured by a Manipulate construct. In your particular case, you could do something like this:

Manipulate[Total[x], {{x, Range[5]}, Range[5], ControlType -> CheckboxBar}]

This creates a CheckboxBar control with five checkboxes all preset to the checked state. The values in the CheckboxBar do not need to be integers.

With[{zooList = {"Cow", "Walrus", "Zebra", "Lion"}}, 
  If[Length[x] === 0, "I want to see nothing at the zoo.", 
   StringJoin[{"I want to see a ", Riffle[x, ", "], 
     " at the zoo."}]], {{x, zooList}, zooList, 
   ControlType -> CheckboxBar}]]
share|improve this answer

Initialization for CheckboxBar works pretty much as for any type of control.

{{checkBoxes, initial-checked-values, ""}, value-list, ControlType -> CheckboxBar}]

For example,

Manipulate[Row[{"Boxes checked: ", Length@checkBoxes}],
  {{checkBoxes, {1, 3}, ""}, {1, 2, 3, 4}, ControlType -> CheckboxBar}]

will produce the following initial state when evaluated.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.