最近在学习Swing,在各种demo中都需要构建JFrame,于是我决定把构建JFrame的代码贴上来,以后就直接复制粘贴了。

public static void main(String[] args) {
        //创建窗体并指定标题
        JFrame frame = new JFrame("BoxlayoutDemo");
        //设置内容面板,根据需要进行修改
        frame.setContentPane(new BoxLayoutDemo());
        //关闭窗体后退出程序
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //自动适配所有控件大小
        frame.pack();
        //设置窗体位置在屏幕中央
        frame.setLocationRelativeTo(null);
        //显示窗体
        frame.setVisible(true);
    }

 

相关文章:

  • 2022-02-14
  • 2022-12-23
  • 2021-05-29
  • 2021-07-20
  • 2021-11-24
  • 2021-07-27
  • 2021-12-22
猜你喜欢
  • 2021-10-05
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案