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

后端 未结 7 1596
孤街浪徒
孤街浪徒 2020-12-10 20:57

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

7条回答
  •  有刺的猬
    2020-12-10 21:46

    It's very simple.

    Here's the code:

    menu.setBackground(Color.DARK_GRAY);
    

    Similarly you can add your own color like GREEN, BLUE, DARK_GRAY, LIGHT_GRAY, BLACK, RED, etc..

    This is the only simple way to change any color of any component in java.

    Note: This is applicable for all components in Java Swing only. it is useless in JavaFX, JFace, SWT but not AWT and Swing

    Thank you,

    Dereck Smith

提交回复
热议问题