Java(GUI)_FlowLayout_18

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

2024-11-04

 

 

 

 

package basic;

import java.awt.FlowLayout;

import javax.swing.*;

/*
 *  배치관리자(Layout)?
 *  - 화면(Frame)에 컴포넌트들을 배치하는 방법을 알려주는 관리자.
 *  - 대표적인 배치관리자의 종류
 *  	1) FlowLayout
 *  	2) BorderLayout
 *  	3) GridLayout
 *  	4) CardLayout
 */

/*
 *  1. FlowLayout 배치관리자
 *  	- 배치 : 좌 -> 우
 *  	- 상단 중앙에 컴포넌트를 배치한다.
 *  	- 화면이 넘칠 경우 밑(아래) 중앙에
 *  	  배치가 됨.
 *  	- 배치관리자를 지정하지 않은 경우,
 *  	  default 로 FlowLayout 배치
 *  	  관리자로 배치가 됨.
 */

public class Ex18_FlowLayout extends JFrame {

	public Ex18_FlowLayout() {
	
		setTitle("FlowLayout 배치관리자");
		
		JPanel container = new JPanel();
		
		//  1. 컴포넌트를 만들어 보자.
		JButton button1 = new JButton("버튼1");
		JButton button2 = new JButton("버튼2");
		JButton button3 = new JButton("버튼3");
		JButton button4 = new JButton("버튼4");
		JButton button5 = new JButton("버튼5");
		
		/*  2. 컴포넌트를 올릴 컨테이너의 배치 관리자를 적용을 하자.
		 * 		형식)
		 * 			container.setLayout(인자);
		 * 
		 * 		인자 형식)
		 * 			new FlowLayout();
		 * 			new FlowLayout(정렬 - 왼쪽, 오른쪽, 중앙(default));
		 * 			new FlowLayout(정렬, 수평간격, 수직간격);
		 * 				수평간격 : 좌우 컴포넌트 사이의 간격 - 기본값 5px
		 */
		
		container.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10));
		
		//  3. 컴포넌트를 컨테이너에 올려야 한다.
		container.add(button1);
		container.add(button2);
		container.add(button3);
		container.add(button4);
		container.add(button5);
		
		//  4. 컨테이너를 프레임에 올려야 한다.
		add(container);
		
		setBounds(100, 100, 300, 300);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		setVisible(true);
	}
	
	public static void main(String[] args) {
		
		new Ex18_FlowLayout();
	}
}

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

Java(GUI)_GridLayout_20  (0) 2024.11.04
Java(GUI)_BorderLayout_19  (0) 2024.11.04
Java(GUI)_ETC_17  (0) 2024.11.04
Java(GUI)_JMenu_16  (0) 2024.11.04
Java(Exception)_Exam_01  (0) 2024.11.04
'Java/기초 내용 정리' 카테고리의 다른 글
  • Java(GUI)_GridLayout_20
  • Java(GUI)_BorderLayout_19
  • Java(GUI)_ETC_17
  • Java(GUI)_JMenu_16
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)_FlowLayout_18
상단으로

티스토리툴바