MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: SetterBar/ButtonBar, Dynamic and the visual appearance of "selected"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104364] Re: SetterBar/ButtonBar, Dynamic and the visual appearance of "selected"
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Thu, 29 Oct 2009 02:56:59 -0500 (EST)
  • References: <hc92ef$een$1@smc.vnet.net>

Jason Ledbetter wrote:
> Folk,
> 
> Once again I'm trying to understand some UI nuances in Mathematica...
> 
> I'm trying to use SetterBar or ButtonBar as selectors for portions of a
> dataset with an action attached. This basically works however when I have an
> action associated with either, the selected button doesn't visually appear
> selected when clicked...
> 
> A sample of what I'm doing is below; my basic goal is to use either of the
> last 2 of these four examples but have the button highlighting act like the
> first two examples.
> 
> Clear[x1, x2, y1, checkSwitch];
>  (* appears to force no default selection w/ SetterBar *)
> (x1 = Null;
>  x2 = Null; y1 = Null;)
> choices = {"one", "two", "three"};
> checkSwitch[button_] := Switch[button, _, Print[button]]
> Panel[{Column[{
>     Style["SetterBars", Bold],
>     Style["No Dynamic, button stays highlighted", Italic],
>     SetterBar[x1, # -> # & /@ choices],
>     Style["Dynamic WITHOUT action, button stays highlighted", Italic],
>     Row[{SetterBar[Dynamic[y1], # -> # & /@ choices], Dynamic[y1]}],
>     Style["Dynamic with action, button does not stay highlighted", Italic],
>     SetterBar[Dynamic[x2, checkSwitch[#] &], # -> # & /@ choices],
>     Style["ButtonBars", Bold],
>     Style["Dynamic with action, button does not stay highlighed", Italic],
>     ButtonBar[# :> checkSwitch[#] & /@ choices]
>     }]
>   }]
> 
> 
> TIA,
> 
> 
> -jbl
> 
> 
Your second to last example should be:

SetterBar[
 Dynamic[x2, (checkSwitch[#]; x2 = #) &], # -> # & /@ choices]

you have to set x2 explicitly when using the two argument form of Dynamic.

hth,

albert


  • Prev by Date: Re: Version 7 Virtual Book
  • Next by Date: Re: problem of syntax.
  • Previous by thread: SetterBar/ButtonBar, Dynamic and the visual appearance of "selected"
  • Next by thread: Re: Re: SetterBar/ButtonBar, Dynamic and the visual