我最初使用的是setSize,但由于java边框和标题空间,导致屏幕内容略大于屏幕.所以我使用了setpreferredSize,现在屏幕尺寸有点太大了.在我的内容的右侧和底侧留下一个空间.
在我的JFrame中:
add(new Board());
setTitle("Rougebot");
setDefaultCloseOperation(EXIT_ON_CLOSE);
//setSize(600, 800);
//getContentPane().setPreferredSize(new Dimension(600,800));
pack();
setLocationRelativeTo(null);
setVisible(true);
setResizable(false);
Run Code Online (Sandbox Code Playgroud)
在我的董事会(JPanel)
setPreferredSize(new Dimension(600,800));
Run Code Online (Sandbox Code Playgroud)