有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java更改菜单栏、项目背景和文本颜色

如何使用UIManager.put(key, value);更改菜单栏和项目颜色

我尝试过这种方法:

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(); }

它不工作,然后我删除UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());,然后它现在就可以工作了,但我需要保持原来的操作系统外观

那么,如何在不使用paintComponent(Graphics g)方法的情况下更改菜单栏和项目的颜色呢


共 (1) 个答案

  1. # 1 楼答案

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