3
$\begingroup$

I tried to align the labels on the buttons of a SetterBarto the button centers. This is my code:

lis = {"1", "2", "3", "dsf"};
SetterBar[Dynamic[buttonValue], 
  Table[lis[[iteration]], {iteration, 1, 4}], 
  BaseStyle -> {Red, Alignment -> {Center, Center}}, {ImageSize -> {100, 50}}]

How do I get the labels of the buttons aligned to their centers? Can any one show me how?

$\endgroup$
2
  • $\begingroup$ I see that you have not Accepted any answers. Please read this FAQ. $\endgroup$
    – Mr.Wizard
    Jan 11, 2013 at 8:30
  • $\begingroup$ there are some syntax problems with the way you have written your options. Alignment is not an option for BaseStyle. Also no need to use Table. Just use lis or {"1", "2", "3", "dsf"}directly. $\endgroup$ Jan 11, 2013 at 8:37

2 Answers 2

8
$\begingroup$
SetterBar[Dynamic[buttonValue], {"1", "2", "3", "dsf"}, BaseStyle -> Red, 
Alignment -> {Center, Center}, ImageSize -> {100, 50}]

Mathematica graphics

$\endgroup$
5
  • $\begingroup$ Nine seconds! :-) $\endgroup$
    – Mr.Wizard
    Jan 11, 2013 at 8:35
  • $\begingroup$ yeah just happened to pass by before shutting the computer down and having a beer :) $\endgroup$ Jan 11, 2013 at 8:35
  • $\begingroup$ Enjoy, Mike. . . . $\endgroup$
    – Mr.Wizard
    Jan 11, 2013 at 8:36
  • $\begingroup$ This answer works, but I have a small quarrel with it. According to the Mathematica documentation, Alignment and ImageSize aren't valid options for SetterBar and the FrontEnd code editor agrees, highlighting them in red. I infer from this that users can not rely on these options working in the future. $\endgroup$
    – m_goldberg
    Jan 11, 2013 at 21:15
  • $\begingroup$ @m_goldberg what you have noticed looks like a bug (red styling) or oversight in the documentation. SetterBar is ultimately just a Grid of Setters and Alignment is a valid option of Setter. $\endgroup$ Jan 11, 2013 at 21:20
3
$\begingroup$

I would change the Table into a Map:

lis = {"1", "2", "3", "dsf"}; 
SetterBar[Dynamic[buttonValue], Style[#, Red] & /@ lis, 
{ImageSize -> {100, 50}}, {Alignment -> Center}]

gives a SetterBar with centered labels.

$\endgroup$

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.