Consider a SetterBar:

SetterBar[1, StringRepeat["q", #] & /@ Range@5]


That is with vertical layout:

SetterBar[1, StringRepeat["q", #] & /@ Range@5, Appearance -> "Vertical"]


Two things are different:

First, the unpressed buttons look differently in vertical than in horizontal layout, because the vertical layout has a mouse-over behavior, which horizontal layout doesn't.


Second, the buttons are nicely aligned by the width of the longest element, but when you click one more time on the already selected button, it shrinks to the length of the string.


I tried to construct a setter bar myself, using Setter:

Column[Setter[Dynamic@x, #, StringRepeat["q", #]] & /@ Range@5]


Looks normal now (no mouse-over behavior), but the same story with the button changing its appearance when double clicked. Apparently, we can use ImageSize to fix this:

Column[Setter[Dynamic@x, #, StringRepeat["q", #], ImageSize -> 100] & /@ Range@5]


I thought I can port this to SetterBar, and it works, but the FE complains that the ImageSizeis not a valid option for SetterBar:

SetterBar[1, StringRepeat["q", #] & /@ Range@5, 
    Appearance -> "Vertical", ImageSize -> 100]


Also, the buttons seem to be next to each other, not like in the column of Setters, so I added ImageMargins, and it works again, but the FE doens't like it either:

SetterBar[1, StringRepeat["q", #] & /@ Range@5, 
    Appearance -> "Vertical", ImageSize -> 100, 
    ImageMargins -> {{0, 0}, {5, 0}}]


Also, the appearance is still "mouse-over" like.


1) What happens with SetterBarwhen I change the layout from horizontal to vertical? Why the appearance of the buttons changes to "mouse-over"? Can we control it?

2) Why the FE complains about options for SetterBar that work fine? Is this a normal behavior? Is this is bug? Are the other examples of the similar behavior?

  • 1
    $\begingroup$ This is not a well-focused question. It jumps around asking a number of different questions about the behavior of Setter and SetterBar. You seem to want someone to write a treatise on how these controls work -- and on more than one OS as well. I could give a work around for the problem you start with, the strange (and I think buggy) behavior of SetterBar when double-clicked. But why bother since it's only one tiny part of a multipart question, and I am not prepared to tackle the whole shebang $\endgroup$ – m_goldberg Jun 9 '17 at 21:19
  • $\begingroup$ I don't seem to have the same trouble with V11.1.1 on a Mac. $\endgroup$ – Michael E2 Jun 10 '17 at 1:15
  • $\begingroup$ @m_goldberg Well, the intention was to give a background, and of course I could ask few smaller questions. I thought it would be good for people to read, because this site is also about information sharing, not just Q&A style. Correct me if this is wrong. If I have to pick, I would pick the one about incorrect FE behavior parsing options (which is also how I would fix the double-clicked behavior). This is truly annoying. Others are mostly platform specific. Should I make a new question? $\endgroup$ – Stitch Jun 10 '17 at 1:41
  • $\begingroup$ Not sure I understand "too broad" and "not sure what you are asking" close votes -- I asked three structured questions (and I deleted one to make it even more explicit), now there are two questions. What is broad here? $\endgroup$ – Stitch Jun 10 '17 at 18:23

To keep button size, one option would be to add StringPadRight

SetterBar[1, StringPadRight @ ( StringRepeat["q", #] & /@ Range@5 ), 
Appearance -> {"Vertical", "Button"}]

enter image description here

To diminish margins one possible way is to add "AbuttingLeft", i.e.

 SetterBar[1, StringPadRight @ ( StringRepeat["q", #] & /@ Range@5 ), 
 Appearance -> {"Vertical", "AbuttingLeft"}]

enter image description here

As a trade-off, one more documented option is to use Appearance->"Palette".

enter image description here

Also notice that at my Mac OS with V10.3 "Horizontal" appearance behaves in the same way (with small move of the right side of double-clicked buttons).

enter image description here

For Manipulate it is also possible to use ImageSize and Alignment via Row like so:

{{s, 1}, (# -> 
  Row[{#}, ImageSize -> 39, Alignment -> Center]) & /@ 
 (StringRepeat["q", #] & /@ Range@5), SetterBar, Appearance -> "Vertical"}, 
 ControlPlacement -> Left]

@MichaelE2's warning concerning size parameters applies here as well.


I usually use Pane to solve such alignment problems. String padding in a variable-width font does not produce reliable results, and Pane can be used to get around that. (Fortunately or unfortunately, a vertical SetterBar automatically pads out the buttons to be the same sizes, and I cannot check this on Windows.)

One of the issues is to determine the dimensions to use for Pane. In particular, the width depends on the style in which the SetterBar is ultimately displayed. When the style is unknown, it can be a challenge to get it right. Usually, I don't worry if the dimensions are little too large, and estimate by trial and error. However, sometimes one wants to get it exactly right, or at least exactly the same as something else. For that one can apply Rasterize to the string in the display style.

strings = StringRepeat["q", #] & /@ Range@5;
width = First@Rasterize[#, "BoundingBox"] & /@ strings // Max
(*  39  *)

SetterBar[1, Pane[#, width, Alignment -> Center] & /@ strings, Appearance -> {"Vertical"}]

Mathematica graphics

For another style, do this:

style = "Label";
width = First@Rasterize[Style[#, style], "BoundingBox"] & /@ styledstrings // Max
(*  28  *)

SetterBar[1, Pane[#, width, Alignment -> Center] & /@ strings, Appearance -> {"Vertical"},
 BaseStyle -> style]

Mathematica graphics

For a Manipulate setter bar, use the "ManipulateLabel" style:

style = "ManipulateLabel";
width = First@Rasterize[Style[#, style], "BoundingBox"] & /@ styledstrings // Max
(*  27  *)

 {{s, "q"}, # -> Pane[#, width, Alignment -> Center] & /@ strings, 
  SetterBar, Appearance -> {"Vertical"}, ControlPlacement -> Left}

Mathematica graphics

One can compare the width with the default Manipulate, or with other values for width, with

Grid[List /@ {man1, man2,...}, Spacings -> 0, 
 Dividers -> {{1 -> Thin, 2 -> Thin}, None}]

Below are the widths in the "ManipulateLabel" style of the strings padded with spaces. They vary considerably.

First@Rasterize[Style[#, style], "BoundingBox"] & /@ 
 StringPadRight@(StringRepeat["q", #] & /@ Range@5)
(*  {15, 19, 21, 25, 27}  *)

For a fixed-width font, there is no such problem.

First@Rasterize[#, "BoundingBox"] & /@ 
 StringPadRight@(StringRepeat["q", #] & /@ Range@5)
(*  {39, 39, 39, 39, 39}  *)
  • $\begingroup$ I don't fully understand the OP's remarks "appearance is still 'mouse-over'" and "AutoAction option doesn't work here naturally, as this is about automatic push, not the appearance," or I would try to address them. There is no Appearance "mouse-over." AutoAction works (naturally), but perhaps the OP means it is not desired. In that case AutoAction -> False works (or should as it does on my computer). $\endgroup$ – Michael E2 Jun 10 '17 at 17:22
  • $\begingroup$ Thank you! You are right. This is actually not relevant as I understand it now -- I just thought the AutoAction is responsible for changing the shape of the buttons when the mouse cursor is over, but obviously it is not what we need for this. Will edit the question now. $\endgroup$ – Stitch Jun 10 '17 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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