Java의 JFrame 창 크기는 어떻게 지정된 창 크기를 생성하지 않습니까?
문제
나는 지금 당장 게임을하려고 노력하고 있지만, 전에도이 문제를 겪었습니다. 특정 창 크기 (예 : 1024 x 768)를 지정하면 생성 된 창이 지정된 것보다 약간 큽니다. 매우 성가신. 이에 대한 이유가 있습니까? 생성 된 창이 실제로 조금 더 크지 않고 원하는 크기가되도록 어떻게 수정합니까? 지금까지 나는 항상 돌아가서 원하는 결과를 얻을 때까지 한 번에 몇 픽셀 크기를 수동으로 조정했지만, 그게 오래되었습니다. 내가 사용할 수있는 공식이 있다면 내 변수에서 탁월한 픽셀을 추가/빼기 위해 얼마나 많은 픽셀을 추가/빼기가 필요한지 알려줄 것입니다!
추신 : 내 OS가 이것의 요인이 될 수 있는지 모르겠지만 W7X64를 사용하고 있습니다.
private int windowWidth = 1024;
private int windowHeight = 768;
public SomeWindow() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(windowWidth, windowHeight);
this.setResizable(false);
this.setLocation(0,0);
this.setVisible(true);
}
해결책
Windows가 작성하는 총 프레임이 내가 지정한 정확한 크기가되기를 원합니다.
나는 당신의 문제를 이해하지 못합니다. 당신의 게시 SSCCE 그것은 문제를 보여줍니다.
다음과 같은 코드를 실행하는 경우
frame.setResizable(false);
frame.setSize(1024, 768);
frame.setVisible(true);
System.out.println(frame.getSize());
java.awt.dimension [width = 1024, height = 768]을 표시합니다.
내가 사용할 수있는 공식이 있다면 내 변수에서 탁월한 픽셀을 추가/빼기 위해 얼마나 많은 픽셀을 추가/빼기가 필요한지 알려줄 것입니다!
어쩌면 당신은 타이틀 바와 국경이 차지하는 공간을 언급하고 있습니까?
import java.awt.*;
import javax.swing.*;
public class FrameInfo
{
public static void main(String[] args)
{
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle bounds = env.getMaximumWindowBounds();
System.out.println("Screen Bounds: " + bounds );
GraphicsDevice screen = env.getDefaultScreenDevice();
GraphicsConfiguration config = screen.getDefaultConfiguration();
System.out.println("Screen Size : " + config.getBounds());
JFrame frame = new JFrame("Frame Info");
System.out.println("Frame Insets : " + frame.getInsets() );
frame.setSize(200, 200);
System.out.println("Frame Insets : " + frame.getInsets() );
frame.setVisible( true );
System.out.println("Frame Size : " + frame.getSize() );
System.out.println("Frame Insets : " + frame.getInsets() );
System.out.println("Content Size : " + frame.getContentPane().getSize() );
}
}
다른 팁
획득 된 창 크기가 묻는 것이 아니라고 말할 때, 당신은 창문에 대해 장식과 함께 이야기하고 있습니까?
실제로, 창 크기는 OS 특정 창 장식없이 정의됩니다.
추가하십시오
this.setUndecorated(true);
전에
this.setVisible(true);