▷ GridLayout
→ 컴포넌트를 테이블(표) 형태로 배치하는 레이아웃
→ 행, 열 형태의 구조를 가지며, 배치되는 컴포넌트의 크기가 균등함
→ GridBagLayout 사용 시 크기가 다른 행, 열 구조 편성 가능
→ 첫 행의 좌측열부터 우측열 방향, 다음행의 좌측열부터 우측열 순으로 배치
→ BorderLayout과 마찬가지로 컨테이너 크기가 변경되면 컴포넌트의 크기만 변경되고,
컴포넌트의 배치 위치는 변경되지 않음
ex_layout.Clone_Ex4.java
package ex_layout;
import java.awt.*;
import javax.swing.*;
public class Clone_Ex4 {
public Clone_Ex4() {
showFrame();
}
public void showFrame() {
JFrame f = new JFrame("Clone_Ex4");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setBounds(600,300,600,600);
f.setLayout(new GridLayout(3,2,10,20)); // 3행, 2열, 수평간격10, 수직간격20
JButton btn1 = new JButton("Button1");
JButton btn2 = new JButton("Button2");
JButton btn3 = new JButton("Button3");
JButton btn4 = new JButton("Button4");
JButton btn5 = new JButton("Button5");
f.add(btn1);
f.add(btn2);
f.add(btn3);
f.add(btn4);
f.add(btn5);
f.setVisible(true);
}
public static void main(String[] args) {
new Clone_Ex4();
}
}
수업시간에 한 내용을 Clone 파일을 만들어 작성함
FlowLayout은 객체생성시 정렬방식을 파라미터로 넘겨주고
GridLayout은 행,열,수평간격,수직간격을 파라미터로 넘겨준다.
'JAVA' 카테고리의 다른 글
swing (Container) (0) | 2022.02.26 |
---|---|
swing (Component) (0) | 2022.02.26 |
swing (Layout 변경) (0) | 2022.02.26 |
swing (Layout) (0) | 2022.02.26 |
Swing(event_handling) (0) | 2022.02.23 |