JFrame Frame 의 하위 클래스입니다. 프레임에 추가된 클래스 및 구성 요소를 해당 콘텐츠라고 하며, 이들은 contentPane에서 관리합니다. . contentPane 을 사용하기 위해 JFrame에 구성 요소를 추가할 수 있습니다. 대신 . JFrame은 창 과 같습니다. 테두리, 제목 및 버튼이 있습니다. JFrame.을 사용하여 대부분의 자바 스윙 애플리케이션을 구현할 수 있습니다.
기본적으로 JFrame은 왼쪽 상단 위치에 표시될 수 있습니다. 화면의. setLocationRelativeTo() 를 사용하여 JFrame의 중심 위치를 표시할 수 있습니다. 창 의 방법 수업.
구문
public void setLocationRelativeTo(Component c)
예시
import javax.swing.*;
import java.awt.*;
public class JFrameCenterPositionTest extends JFrame {
public JFrameCenterPositionTest() {
setTitle("JFrameCenter Position");
add(new JLabel("JFrame set to center of the screen", SwingConstants.CENTER), BorderLayout.CENTER);
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null); // this method display the JFrame to center position of a screen
setVisible(true);
}
public static void main (String[] args) {
new JFrameCenterPositionTest();
}
} 출력
