자바 JFC 구성 및 일반 클래스 활용 JTextArea

자바 JFC 구성 및 일반 클래스 활용 JTextArea


JTextArea
JTextArea는 JScrollPane을 사용해야 스크롤이 된다 .

ex )

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.awt.*;
import javax.swing.*;

class Round22_Ex01_Sub extends JFrame {// JFrame을 상속받는다
private Container con;
private BorderLayout bl = new BorderLayout();
private JButton bt = new JButton("1");
private JButton bt1 = new JButton("2");
private JTextArea ta = new JTextArea();
// JTextArea의 객체를 선언한다
private JScrollPane jsp = new JScrollPane(ta);

// 스크롤을 사용할려면 jsp에 담아서 사용해야한다
public Round22_Ex01_Sub() {
super("제목");
this.init();
this.start();
im = new ImageIcon("title.gif");
this.setIconImage(im.getImage());
this.setSize(300, 200);
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension di = tk.getScreenSize();
Dimension di1 = this.getSize();
int xpos = ((int) di.getWidth() / 2 - (int) di1.getWidth() / 2);
int ypos = ((int) di.getHeight() / 2 - (int) di1.getHeight() / 2);
this.setLocation(xpos, ypos);
this.setVisible(true);
}

public void init() {
con = this.getContentPane();// 다중 Panel에서의 기본 작업영역 획득
con.setLayout(bl);
JPanel jp = new JPanel(new FlowLayout(FlowLayout.RIGHT));
jp.add(bt);
jp.add(bt1);
con.add("North", jp);
jsp.setWheelScrollingEnabled(true);
// 스크롤링의 유무를 선언한다 스크롤링이 되게 선언 .
con.add("Center", jsp);
// 폼 구성 영역 (초기화 영역)
}

public void start() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Frame의 x버튼을 눌렀을 때의 Event
// 이벤트나 기타 액션의 영역
}
}

public class Round22_Ex01 {
public static void main(String[] ar) {
Round22_Ex01_Sub es = new Round22_Ex01_Sub();
}
}

Share