JAVA - Container
컴포넌트들을 담을수 있는 객체이다.
1
2
3
4
5
| Container c = getContentPane();
c.setLayout(grid);
c.add(new JLabel("이름"));
c.add(new JTextField(20));
|
JAVA - GridLayout
레이아웃의 한 종류로 격자형태로 배치할 수 있게 해주는 레이아웃이다.
1
2
3
4
| GridLayout grid = new GridLayout(1, 10); //<--레이아웃의 크기를 인수로 작성
Container c = getContentPane();
c.setLayout(grid);
|
버튼형태의 컴포넌트이다.
1
2
3
4
| JButton b = new JButton(Integer.toString(i));
b.setLocation(i*50, 0);
b.setSize(50, 200);
c.add(b);
|
JAVA - setOpaque
JLabel은 배경색이 기본적으로 투명이기때문에 true로 설정을 해주어야 배경색이 적용된다.
1
2
| JLabel la = new JLabel();
la.setOpaque(true);
|
JAVA - setLocation
해당 컴퍼넌트의 위치를 설정해주는 함수이다.
1
2
| JLabel la = new JLabel();
la.setLocation(10, 10);
|
JAVA - JLabel
컴퍼넌트의 한 종류이다.
1
| JLabel la = new JLabel();
|
JAVA - ImageIcon
1
2
| ImageIcon normalIcon = new ImageIcon("images/normalIcon.jpg");
JLabel label = new JLabel("보고싶으면 전화하세요.", normalIcon, SwingConstants.CENTER);
|
JAVA - JCheckBox
체크박스 형태의 컴포넌트이다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| public CheckBoxEx() {
setTitle("체크박스 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
ImageIcon cherryIcon = new ImageIcon("images/cherry.jpg");
ImageIcon selectedCherryIcon = new ImageIcon("images/selectedCherry.jpg");
JCheckBox apple = new JCheckBox("사과");
JCheckBox pear = new JCheckBox("배", true);
JCheckBox cherry = new JCheckBox("체리", cherryIcon);
cherry.setBorderPainted(true);
cherry.setSelectedIcon(selectedCherryIcon);
c.add(apple);
c.add(pear);
c.add(cherry);
setSize(250, 150);
setVisible(true);
}
|
JAVA - setResizable
GUI를 통해 나타난 창을 조절하지 못하게 하는 메소드.
JAVA - JTextField
텍스트를 입력할수 있게 하는 컴포넌트이다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| public TextFieldEx() {
setTitle("텍스트필드 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.add(new JLabel("이름"));
c.add(new JTextField(20));
c.add(new JLabel("학과"));
c.add(new JTextField("컴퓨터공학과", 20));
c.add(new JLabel("주소"));
c.add(new JTextField("서울시", 20));
setSize(300,150);
setVisible(true);
}
|
JAVA - TextArea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| public TextAreaEx() {
setTitle("텍스트영역 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.add(new JLabel("입력 후 <Enter> 키를 입력하세요."));
c.add(tf);
c.add(new JScrollPane(ta));
setSize(300,300);
setVisible(true);
}
|
JAVA - JList
일반 리스트와 달리 컨테이너에 담을 수 있는 리스트 형태이다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| private String[] fruits = {"apple", "banana", "kiwi", "mango", "pear", "peach", "berry", "strawberry", "blackberry"};
private ImageIcon[] images = {
new ImageIcon("images/icon1.png"),
new ImageIcon("images/icon2.png"),
new ImageIcon("images/icon3.png"),
new ImageIcon("images/icon4.png")
};
public ListEx() {
setTitle("리스트 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JList<String> strList = new JList<String>(fruits);
c.add(strList);
JList<ImageIcon> imageList = new JList<ImageIcon>();
imageList.setListData(images);
c.add(imageList);
JList<String> scrollList = new JList<String>(fruits);
c.add(new JScrollPane(scrollList));
setSize(300,300);
setVisible(true);
}
|
JAVA - JComboBox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| private String[] fruits = {"apple", "banana", "kiwi", "mango", "pear", "peach", "berry", "strawberry", "blackberry"};
private String[] names = {"kitae", "jaemoon", "hyosoo", "namyun",};
public ComboBoxEx() {
setTitle("콤보박스 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JComboBox<String> strCombo = new JComboBox<String>(fruits);
c.add(strCombo);
JComboBox<String> nameCombo = new JComboBox<String>();
for(int i = 0; i < names.length; i++) {
nameCombo.addItem(names[i]);
c.add(nameCombo);
}
}
|
JAVA - JSlider
슬라이더 형태의 컴포넌트이다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| public SliderEx() {
setTitle("슬라이더 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 200, 100); //?
slider.setPaintLabels(true); //?
slider.setPaintTicks(true); //?
slider.setPaintTrack(true); //?
slider.setMajorTickSpacing(50); //?
slider.setMinorTickSpacing(10); //?
c.add(slider);
setSize(300, 300);
setVisible(true);
}
|