Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It is easy to define a background color for the SetterBar buttons, so that all the buttons that are not pressed have the specified color, while the pressed one is gray. Here is the example:

SetterBar[2, Range[5], Background -> LightBlue]

in which the buttons that are not pressed are LightBlue.

How to make another way around? That is, how to make all buttons gray except the pressed one, which should take a specified color?

share|improve this question
On my system, V9.0.1 on OS X, setting the background color of a setter bar has no effect on the color of the buttons in bar, pressed or unpressed. What is your setup? – m_goldberg Sep 30 '13 at 15:23
@m_goldberg He's probably working on Windows. It is working here. – Kuba Sep 30 '13 at 15:27
@m_goldberg PC, Win7, Mma 9.01 – Alexei Boulbitch Oct 1 '13 at 8:04

There were always problems with getting SetterBar the proper look.

I think the fastest, but not the cleanest, way is to make it with Panel/Pane/Framed:

pan[i_] := Panel[Style[i, Bold, Black, 12], FrameMargins -> 0, ImageSize -> {20, 20}, 
                 Alignment -> Center, Background -> If[x == i, Red, Blue]];

SetterBar[Dynamic@x, Thread[Range[5] -> Table[With[{i = i}, Dynamic@pan[i]], {i, 5}]], 
          Appearance -> "Frameless"]

enter image description here

Watch out on x. Probably you may want to put it into DynamicModule for proper scope.

share|improve this answer
As for the global x, would it not be enough to add a second argument to pan, like so: pan[i_, k_] := Panel[Style[i, Bold, White, 12], FrameMargins -> 0, ImageSize -> {20, 20}, Alignment -> Center, Background -> If[k == i, Red, Blue]]? Also, note that Black is replaces with White; numbers on the button look much better in white when displayed on red and blue backgrounds. – m_goldberg Oct 1 '13 at 6:41
@Kuba Thank you for the suggestion. This is a possibility, of course, and I have it in mind. My question concerned more the built-in Mma options. I just had an impression that I missed something elementary in the documentation, since for me the desire to highlight the pressed button looks more natural than the one of highlighting all except the pressed one. Thank you once more, but let us wait a bit in case something else pops up. – Alexei Boulbitch Oct 1 '13 at 8:15
@AlexeiBoulbitch yes ofcourse :) I'm afraid SetterBar is tough to customize. There were similar questions about button size for it and the solutions were similar. So I think there isn't any built-in functionality. But I would like to see it too, not need to hurry :) – Kuba Oct 1 '13 at 8:20
@m_goldberg Thanks for remarks. :) I agree but I will leave it as it is, I think it will not affect the message which is how to make SetterBar which behaves like OP wants. – Kuba Oct 2 '13 at 7:57

Your Answer


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.