Java Swing Blank JFrame coming up?

风格不统一 提交于 2019-11-27 05:38:29

setVisible(true) has to be the last method called in your Main method. Otherwise nothing may render on the JFrame

why sometimes my application comes up as blank, and sometimes it displays the components. It seems to be sporadic.

It is not sporadic, it happens when you miss a frame.pack() call to tell the frame to pack all its components

Do the following and the frame should display ok:

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