我在设置绘图面板的大小时遇到问题。我想要一个大小为 0f 600,600 的绘图面板。但是我发现绘图面板的大小小于 600,600。似乎框架大小为 600,600,这使得绘图面板更小。如何设置绘图面板大小 600,600 ?
....
public class DrawingBoardWithMatrix extends JFrame {
public static void main(String[] args) {
new DrawingBoardWithMatrix();
}
public DrawingBoardWithMatrix(){
this.getContentPane().setBackground(Color.WHITE);
this.setSize(600, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(new PaintSurface(), BorderLayout.CENTER);
this.setVisible(true);
setResizable(false);
}
我已经更改了代码,但问题仍然存在。此时绘图面板的尺寸大于预期的尺寸尺寸。
public class DrawingBoardWithMatrix extends JFrame {
public static void main(String[] args) {
new DrawingBoardWithMatrix();
}
public DrawingBoardWithMatrix(){
Container c = getContentPane();
c.add(new PaintSurface(), BorderLayout.CENTER);
c.setPreferredSize(new Dimension(600,600));
pack();
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
}