javamenuuimanager

Java - Changing the Menu Bar and Item Background and Text Color


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?


Solution

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