Java Swing Blank JFrame coming up?

前端 未结 2 1490
面向向阳花
面向向阳花 2020-11-30 15:19

I\'m new to swing, and was wondering why sometimes my application comes up as blank, and sometimes it displays the components. It seems to be sporadic. There are no exceptio

相关标签:
2条回答
  • 2020-11-30 16:08

    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);
    
    0 讨论(0)
  • 2020-11-30 16:09

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

    0 讨论(0)
提交回复
热议问题