小编Lin*_*Rom的帖子

将setVisible()函数放在函数的开头是不同的当我把它放在函数的末尾?

我只是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)

java jframe

1
推荐指数
1
解决办法
1107
查看次数

标签 统计

java ×1

jframe ×1