10
$\begingroup$

I want to set the Background color of a PopupMenu to blue. I already searched in the documentation center, but I didn't find any option that seemed suitable.

 PopupMenu[
    Dynamic[x], 
    {"Country1", "Country2", "Country3"}, 
    ImageSize -> {180, 60}, Background -> Blue,
    Alignment -> {Center, Center},
    MenuStyle ->Directive[Orange, 20, Bold]
 ]

enter image description here

$\endgroup$
2
$\begingroup$

To get the look subbu asked for on OS X, I had to override the default appearance of the pop-up menu widget. Here is what I came up with:

PopupMenu[Dynamic@x, {"Country1", "Country2", "Country3"}, "", 
   Row[{Panel[Style[Dynamic@x, Orange, 20, Bold, Background -> Blue], 
           ImageSize -> {160, 60}, Appearance -> None, Background -> Blue, 
           Alignment -> {Center, Center}], 
        Panel[Style["\[FilledDownTriangle]", 16, Bold, 
           Background -> White], ImageSize -> {20, 60}, Appearance -> None, 
           Alignment -> {Center, Center}]}, Frame -> True, 
      FrameMargins -> None], MenuStyle -> Directive[Orange, 20, Bold]]

It produces a control that looks like this:

custom pop-up menu

$\endgroup$
  • $\begingroup$ @m_goldberg.Really I like your code.but How can i set background color for Menu ? $\endgroup$ – subbu Nov 23 '12 at 7:36
2
$\begingroup$

One can get close by using the

{value1 -> label1, value2 -> label2, …}

format for PopupMenu and making the labels with a blue background.

countryList = {"Country1", "Country2", "Country3"}

labelList = Map[
  Row[{
     Spacer[{60, 56, 23}],
     Style[#, Orange, 20, Bold, Background -> Blue],
     Spacer[60]
     },
    Background -> Blue] &,
  countryList]

Mathematica graphics

Now generate a set of rules to be used as the input to PopupMenu

popupRules = Map[countryList[[#]] -> labelList[[#]] &, Range[3]]

Mathematica graphics

Now use the rules as input to PopupMenu

PopupMenu[Dynamic[x],
 popupRules,
 "Country 1",
 ImageSize -> {180, 60},
 Background -> Blue,
 Alignment -> {Center, Center}
 ]

PopupMenu

$\endgroup$
1
$\begingroup$

I am assuming that you made the blue background in a graphics program to show us what you want because on my computer your blue background is obscured by the default appearance.

enter image description here

Setting Appearance->None will fix this ...although on my mac I lose the "guiding up-down arrows" when I do that.

enter image description here

$\endgroup$
  • 1
    $\begingroup$ I'm not sure, but could the OP have meant to ask how to color the pop-up part of the menu blue and not the fixed part? The latter he already colored blue. $\endgroup$ – Sjoerd C. de Vries Nov 22 '12 at 21:30
  • $\begingroup$ @SjoerdC.deVries I assumed he made that in a graphics program because his code does not deliver that screen grab on my computer ...will add a grab. $\endgroup$ – Mike Honeychurch Nov 22 '12 at 21:40
  • 1
    $\begingroup$ It looked like that on my Win7 PC. So, no manual coloring there... $\endgroup$ – Sjoerd C. de Vries Nov 22 '12 at 21:54
  • $\begingroup$ @SjoerdC.deVries interesting. Maybe that is what he meant. I'll wait for him to reply/clarify. Might be worth leaving this answer here for Mac users. $\endgroup$ – Mike Honeychurch Nov 22 '12 at 23:04
  • 3
    $\begingroup$ Why no copyable code? $\endgroup$ – Mr.Wizard Nov 23 '12 at 0:55

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.