JFrame not presenting any Components

独自空忆成欢 提交于 2019-11-27 16:20:49
CoderCroc

Put frame.setVisible(true); after adding components to JFrame, and it will show all the added components. Moreover, you should use specific layout rather than setting bounds for components. You can use a Layout Manager.

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.

you can add this at the end;

frame.pack()

Better your first add components to your variable "panel" and add then your finished panel to the .getContentPane().add().

And the most important issue is that you better call frame.setVisible(true); at the end of your method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!