Java JFrame background color not working

前端 未结 4 1465
名媛妹妹
名媛妹妹 2020-12-11 19:05

I tried using:

frame1.getContentPane().setBackground(Color.yellow);

But it is not working. Can anyone help me?

import java.         


        
4条回答
  •  悲&欢浪女
    2020-12-11 19:38

    Just put your setVisible(true); at the end of your constructor.

    Moreover you had added mainPnl on your JFrame, so changing colour of the JFrame will be useless,

    so instead of writing

    add(mainPnl);
    

    in your GameFrame class, you better be using

    setContentPane(mainPnl);
    

    for frame1.getContentPane().setBackground(Color.YELLOW); to work.

    Hope this might help

    Regards

提交回复
热议问题