javacolorsbackgroundjpopupmenujmenuitem

jPopUpMenu Change rollover background


I would like to change the background color of my jMenuItems on a rollover event :

enter image description here

Now it's blue, I want it white, how can I do ? (I use netbeans GUI)


Solution

  • You can use something like:

    UIManager.put("MenuItem.selectionBackground", Color.WHITE);
    

    Problem is this will change the color for all menu items, even those added to a JMenu.

    To control which menu items are changed you will need to create a custom MenuItem UI to replace the default. You will then need to modify the code to use your custom selection background color.