Почему вызов JFrame.pack () добавляет дополнительное пространство?
Первоначально код, который я использовал, работал нормально, но был немного запутанным. После перемещения некоторых частей метода в конструктор JFrame все работало правильно.
Все, кроме использования pack (), чтобы сделать рамку нужного размера.
Вот оригинальный код:
public class BaseGameFrame extends JFrame {
public static final int WINDOWED = 0;
public static final int UFS = 1;
protected BaseGamePanel gamePanel;
public BaseGameFrame(String title, int pWidth, int pHeight, long period, int windowType){
super(title);
switch(windowType){
case UFS:
this.setUndecorated(true);
Rectangle screenSize = this.getGraphicsConfiguration().getBounds();
pWidth = screenSize.width;
pHeight = screenSize.height;
break;
default: break;
}
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.createPanel(pWidth, pHeight, period);
}
protected void createPanel(final int pWidth, final int pHeight, long period){
this.gamePanel = new BaseGamePanel(pWidth, pHeight, period);
this.add(this.gamePanel);
this.pack();
}
public static void main(String[] args){
new BaseGameFrame("Test", 800, 600, 20L * 1000000L, UFS);
}
}
и вот после его изменения:
public class BaseGameFrame extends JFrame {
protected BaseGamePanel gamePanel;
public BaseGameFrame(String title, VideoType vType, BaseGamePanel gp){
super(title);
switch(vType){
case UFS:
this.setUndecorated(true);
Rectangle screenSize = this.getGraphicsConfiguration().getBounds();
gp.setPDimensions(new Dimension(screenSize.width, screenSize.height));
break;
default: break;
}
this.add(gp);
this.pack();
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
BaseGamePanel gp = new BaseGamePanel(800, 600, 20L * 1000000L);
new BaseGameFrame("Test", VideoType.UFS, gp);
}
}
Я не совсем уверен, в чем проблема .. но что в итоге происходит так: