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 can I dynamically change the appearance of b? Strangely it works for the Enabled state but not for the Appearance.

Thanks.

Manipulate[
  bAppearance = If[a > 1, "Open", "Closed"]; 
  bEnabled = If[a > 2, False, True];
  Plot[Sin[a x + b], 
  {x, 0, 6}], {a, 1, 4}, {b, 0, 10, Appearance -> Dynamic@bAppearance}]
share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

Here's one way around it -- make the Manipulator dynamic:

Manipulate[
 bAppearance = If[a > 1, "Open", "Closed"];
 bEnabled = If[a > 2, False, True];
 Plot[Sin[a x + b], {x, 0, 6}],
 {a, 1, 4}, {b, 0, 10, Dynamic@Manipulator[##, Appearance -> bAppearance] &}]

The Manipulator is recreated when bAppearance changes. It won't be recreated when b changes because b will be wrapped in Dynamic when the control is created.

share|improve this answer
add comment

You can change the appearance of most controls, but the Manipulator Control has something in it that prevents its dynamic behavior (a bug or a feature ?).

Look (with a slider):

Manipulate[
 {Dynamic@a, Plot[Sin[a x + b], {x, 0, 6}]},
 {a, 1, 4},
 {b, 0, 1, ControlType -> Slider, 
  Appearance -> Dynamic[If[a > 1, {Tiny}, {Large}]]}]

enter image description here

Now the same with a Manipulator (showing it doesn't work):

Manipulate[
 {Dynamic@a, Plot[Sin[a x + b], {x, 0, 6}]},
 {a, 1, 4},
 {b, 0, 1, ControlType -> Manipulator, 
  Appearance -> Dynamic[If[a > 1, {Tiny}, {Large}]]}]

enter image description here

share|improve this answer
    
Interesting, but the problem is that the Sliders don't have an "Open", "Closed" state and I am using Manipulators for that reason. I would like the users to be able to input a value directly. –  dabd May 3 '13 at 15:47
    
@dabd I know. I'm trying to tell you that that isn't going to work easily –  belisarius May 3 '13 at 15:50
add comment

Here's one approach, perhaps not as straightforward as might be hoped for but it works:

Manipulate[
 Plot[Sin[a x + b], {x, 0, 6}],

 {a, 1, 4},

 Row@List@With[{choice = Dynamic[If[a < 2, 1, 2]]},
    Overlay[{
      Control[{b, 0, 1, Appearance -> "Closed"}],
      Control[{b, 0, 1, Appearance -> "Open"}]},
     {choice}, choice]]]

Also take a look at the ImageSize settings for Overlay, if the switching has resizing issues.

Edit Oops. We can just do it this way:

Manipulate[
 Plot[Sin[a x + b], {x, 0, 6}],

 {a, 1, 4},

 Row@List@Dynamic[If[a < 2,
     Control[{b, 0, 1, Appearance -> "Closed"}],
     Control[{b, 0, 1, Appearance -> "Open"}]]]]
share|improve this answer
    
Very nice thanks! –  dabd May 3 '13 at 21:04
add comment

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.