forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextEntryBox2.java
More file actions
40 lines (31 loc) · 1.05 KB
/
Copy pathTextEntryBox2.java
File metadata and controls
40 lines (31 loc) · 1.05 KB
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
//file: TextEntryBox2.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class TextEntryBox2 {
public static void main(String[] args) {
JFrame frame = new JFrame("Text Entry Box");
final JTextArea area = new JTextArea();
area.setFont(new Font("Serif", Font.BOLD, 18));
area.setText("Howdy!\n");
area.setEditable(false);
Caret caret = area.getCaret();
System.out.println(caret);
((DefaultCaret)caret).setUpdatePolicy( DefaultCaret.ALWAYS_UPDATE );
final JTextField field = new JTextField();
Container content = frame.getContentPane();
content.add(new JScrollPane(area), BorderLayout.CENTER);
content.add(field, BorderLayout.SOUTH);
field.requestFocus();
field.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent ae) {
area.append(field.getText( ) + '\n');
field.setText("");
}
});
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setSize(200, 300);
frame.setVisible(true);
}
}