컴퓨터공학부/고급객체지향프로그래밍(Java)
GridLayout 클래스
동구밖과수원
2010. 10. 29. 10:12
컴포넌트들을 격자 모양으로 배치한다. 모든 컴포넌트들의 크기는 같게 되며 컨테이너의 모든 공간은 컴포넌트로 채워진다. 윈도우의 크기를 바꾸면 GridLayout은 컴포넌트의 크기를 변경하여 윈도우의 크기에 맞춘다.
1 |
2 |
3 |
4 |
5 |
|
import javax.swing.*;
import java.awt.*;
public class MyFrame2 extends JFrame
{
public MyFrame2()
{
this.setTitle("GridLayoutTest");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(0,3));
panel.add(new JButton("1"));
panel.add(new JButton("2"));
panel.add(new JButton("3"));
panel.add(new JButton("4"));
panel.add(new JButton("5"));
this.add(panel);
this.pack();//프레임을 패널 크기에 맞추기
this.setVisible(true);
}
}