Java(GUI)_BorderLayout_19

2024. 11. 4. 18:19·Java/기초 내용 정리

2024-11-04

 

 

 

package basic;

import java.awt.BorderLayout;

import javax.swing.*;

/*
 *  2. BorderLayout 배치관리자
 *  	- 배치 : 동쪽, 서쪽, 남쪽, 북쪽, 중앙
 */

public class Ex19_BorderLayout extends JFrame {
	
	public Ex19_BorderLayout() {
	
		setTitle("BorderLayout 배치관리자");
		
		JPanel container = new JPanel();
		
		JButton button1 = new JButton("North");
		JButton button2 = new JButton("South");
		JButton button3 = new JButton("East");
		JButton button4 = new JButton("West");
		JButton button5 = new JButton("Center");
		
		/*  1. 컴포넌트를 올릴 컨테이너의 배치관리자를 정하자.
		 *  형식)2
		 *  	new BorderLayout()
		 *  	new BorderLayout(수평간격, 수직간격)
		 *  		- 수평간격 : 좌우 컴포넌트 사이의 간격 - 기본값 0px
		 *  		- 수직간격 : 상하 컴포넌트 사이의 간격 - 기본값 0px
		 */
		
		container.setLayout(new BorderLayout(10, 20));
		
		//  2. 컴포넌트를 컨테이너에 올려야 한다.
		container.add(button1, BorderLayout.NORTH);
		container.add(button2, BorderLayout.SOUTH);
		container.add(button3, BorderLayout.EAST);
		container.add(button4, BorderLayout.WEST);
		container.add(button5, BorderLayout.CENTER);
		
		//  3. 컨테이너를 프레임에 올려야 한다.
		add(container);
		
		setBounds(100, 100, 300, 300);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		setVisible(true);
	}

	public static void main(String[] args) {
		
		new Ex19_BorderLayout();
	}
}

'Java > 기초 내용 정리' 카테고리의 다른 글

Java(GUI)_Layout_21  (0) 2024.11.04
Java(GUI)_GridLayout_20  (0) 2024.11.04
Java(GUI)_FlowLayout_18  (0) 2024.11.04
Java(GUI)_ETC_17  (0) 2024.11.04
Java(GUI)_JMenu_16  (0) 2024.11.04
'Java/기초 내용 정리' 카테고리의 다른 글
  • Java(GUI)_Layout_21
  • Java(GUI)_GridLayout_20
  • Java(GUI)_FlowLayout_18
  • Java(GUI)_ETC_17
mw41817
mw41817
일생의 개발 기록 저장소
  • mw41817
    IT 개발 일지
    mw41817
    • Index (487)
      • HTML (36)
        • 기초 내용 정리 (36)
      • CSS (29)
        • 기초 내용 정리 (29)
      • JavaScript (60)
        • 기초 내용 정리 (60)
      • JQuery (38)
        • 기초 내용 정리 (38)
      • Java (232)
        • 기초 내용 정리 (232)
      • JSP (46)
        • 기초 내용 정리 (46)
      • Spring, Boot (31)
        • 기초 내용 정리 (31)
      • DB (5)
        • Oracle SQL (5)
      • Code WorkBook (6)
        • programmers (6)
        • Baekjoon (0)
      • 기타 (1)
        • 유용한 사이트 (3)
  • 전체
    오늘
    어제
  • 글쓰기 관리
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 카테고리
    • 주인장 GitHub
  • 공지사항

  • 인기 글

  • 태그

    html #코딩 #프로그래밍 #기초
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.0
mw41817
Java(GUI)_BorderLayout_19
상단으로

티스토리툴바