-1

How to change the Menu Bar and Item Color using UIManager.put(key, value);.

I have tried this method:

try {

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    UIManager.put("MenuBar.background", Color.black);
    UIManager.put("MenuBar.foreground", Color.white);
    UIManager.put("MenuItem.background", Color.black);
    UIManager.put("MenuItem.foreground", Color.white);

    new Window();

}
catch(Exception e) { e.printStackTrace(); }

It doesn't work, then I remove the UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());, then it will now work, but I need to stick to the original Operating System Look and Feel.

So how do I change the color of a Menu Bar and Item without using the paintComponent(Graphics g) method?

1 Answers1

0
  UIManager.put("MenuItem.background", Color.CYAN);
  UIManager.put("MenuItem.opaque", true);
  • 1. Do you really need `opaque`? 2. How about the font color/foreground? Is my example great? –  Jan 29 '18 at 12:03
  • Sorry for the delay, I have my third year exams when you answered, which the question is not in my exams, just I have a project. –  Jan 29 '18 at 12:05
  • The opaque option must be used to take the color defined in the UIManager – David Caceres Jan 31 '18 at 22:32
  • I've tested it, and it worked, but how about the JMenuBar? –  Feb 17 '18 at 04:08