Change background and text color of JMenuBar and JMenu objects inside it

KernelPanic picture KernelPanic · Mar 26, 2013 · Viewed 41.5k times · Source

How can I set custom background color for JMenuBar and JMenu objects inside it? I tried .setBackgroundColor and it does not work!

Answer

tenorsax picture tenorsax · Mar 27, 2013

You would probably need to change opacity of menu items, ie:

JMenuItem item= new JMenuItem("Test");
item.setOpaque(true);
item.setBackground(Color.CYAN);

You can also achieve that globally using UIManager, for example:

UIManager.put("MenuItem.background", Color.CYAN);
UIManager.put("MenuItem.opaque", true);