How to change the background color on a Java panel?

后端 未结 4 828

Right now, the background I get is a grey. I want to change it to black. I tried doing something like setBackground(color.BLACK); but it didnt work. Any suggestions?

4条回答
  •  长发绾君心
    2021-02-07 16:54

    You could call:

    
    getContentPane().setBackground(Color.black);
    
    

    Or add a JPanel to the JFrame your using. Then add your components to the JPanel. This will allow you to call

    
    setBackground(Color.black);
    
    

    on the JPanel to set the background color.

提交回复
热议问题