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.

I needed to make 2 slider inter-dependent. Slider b in this example can't be larger than slider a. When I move slider b and release the mouse it will snap back if it stopped at a value larger than current value of a slider.

I noticed this works first time. But when I move the slider b again, it no longer snaps back.

I found this is becuase I had ContinuousAction -> False. But this should not have this effect. This option says that while I am sliding there should be no update to the Manipulate expression. So, once I have released the mouse, my snap logic code should execute each time. In this example below I show that it does not.

Do you think this behaviour is correct? I think it is not. I needed to have the ContinuousAction -> False there for other reasons (I do not want large computation to occur while I am moving the slider, only when I release the slider).

Here is an example that works. Notice no use of ContinuousAction -> False, hence the default is True

Manipulate[
 {a, b},

 Grid[{{
    "a", Manipulator[Dynamic[a,{a = #; If[b > a, b = a]} &], {1, 10, 1}], Dynamic[a]
    }, {
    "b", Manipulator[Dynamic[b,{b = #; If[b > a, b = a]} &], {1, 10, 1}], Dynamic[b]
    }}],
 {{a, 5}, None},
 {{b, 3}, None}
 ]

You can move the slider b to the right as much as you want, release the mouse, and keep doing that. It will never go pass the value in a. Now see what happens with this example:

 Manipulate[
 {a, b},

 Grid[{{
    "a", Manipulator[Dynamic[a,
      {a = #; If[b > a, b = a]} &], {1, 10, 1},ContinuousAction -> False], Dynamic[a]
    }, {
    "b", Manipulator[Dynamic[b,
      {b = #; If[b > a, b = a]} &], {1, 10, 1},ContinuousAction -> False], Dynamic[b]
    }}],
 {{a, 5}, None},
 {{b, 3}, None}
 ]

Move the slide b again. The first time you'll notice the snaps back. But now try to move it again to the right, and you'll see it does not snap back again. The logic inside the Dynamics is not being called.

Question: Do you think this behaviur is correct based on the help:

With ContinuousAction->False, updates are supplied only when the controls are in their final position, say as determined by the release of a mouse button.

For me, the above says one thing, and what I see is something else. What seems to happen is that Mathematica takes the second movement of the same slider as part of the first movement. Even though one has released the mouse in between. But these should be separate movement and not one continuous one.

thanks

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I would recommend a simpler version to achieve this. It works for all settings of ContinuousAction.

Manipulate[If[a < b, b = a]; {a, b}, {{a, 5}, 1, 10, 1}, {{b, 5}, 1, a, 1}]

Manipulate[If[a < b, b = a]; {a, b}, {{a, 5}, 1, 10, 1, 
  ContinuousAction -> False}, {{b, 5}, 1, a, 1, ContinuousAction -> False}]
share|improve this answer
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.