Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
1  
Would you please give an example of the code you are working on? –  Mr.Wizard Mar 20 at 15:14
    
Generally speaking, all controls are set to the initial value(s) of the variables, if any. –  Michael E2 Mar 20 at 15:16

2 Answers 2

up vote 0 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"}}, 
 Manipulate[
  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.

manipulate

share|improve this answer

Your Answer

 
discard

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.