我只是Java GUI编程的新手,我遇到的问题是,当我将setVisible()函数放在构造函数调用的函数的开头时,我的面板中的组件会丢失,但是当它在最后时它工作正常.见下面的代码:
public static void main(String[] args)
{
new MainClass();
}
public MainClass()
{
setFrame();
}
private void setFrame()
{
JFrame frame = new JFrame();
frame.setSize(400,400);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Some area where the object of my components inside the panel is created and initialized.
// If I just place a label and a button, it will appear on the panel. However if I add the JTextArea, all the components in my panel is gone. Just like the …Run Code Online (Sandbox Code Playgroud)