I've had this problem many times before while using Java swing. I run the program, and nothing at all displays but the window; the moment you resize it even by a pixel, everything appears perfectly. Could anyone please tell me why this is happening?
Thanks.
问问题
1740 次
2 回答
3
总是从头开始invokeLater()
,使用布局管理器,最后pack()
制作框架。setVisible()
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(0, 1));
panel.add(...);
panel.add(...);
f.add(new JScrollPane(panel));
f.pack();
f.setVisible(true);
}
});
于 2012-11-06T13:41:49.460 回答
0
确保以下代码将出现在 GUI 代码的末尾。
frame.setSize(500,500); // size of the frame
frame.setVisible(true); // make frame window visible
于 2012-11-06T09:52:25.220 回答