JFrame not presenting any Components

后端 未结 4 1777
遇见更好的自我
遇见更好的自我 2020-12-04 03:00

I am using the following code to create a very simple JFrame, but for some reason it doesn\'t show any components, just a blank frame. Why is this happening? I

4条回答
  •  春和景丽
    2020-12-04 03:45

    You have to move frame.setVisible(true); to the end of the method; the visibility must be set to true after you have added the components.

    Alternatively, you can add the following to the end of your method:

    frame.revalidate();
    frame.repaint();
    

    to revalidate and repaint the frame with the newly added components although I recommend the former method.

提交回复
热议问题