Java Reference
In-Depth Information
Display 18.8
A Text Area with Scroll Bars
(part 2 of 3)
32
JPanel buttonPanel =
new
JPanel();
33
buttonPanel.setBackground(Color.LIGHT_GRAY);
34
buttonPanel.setLayout(
new
FlowLayout());
35
JButton memo1Button =
new
JButton("Save Memo 1");
36
memo1Button.addActionListener(
this
);
37
buttonPanel.add(memo1Button);
38
JButton memo2Button =
new
JButton("Save Memo 2");
39
memo2Button.addActionListener(
this
);
40
buttonPanel.add(memo2Button);
41
JButton clearButton =
new
JButton("Clear");
42
clearButton.addActionListener(
this
);
43
buttonPanel.add(clearButton);
44
JButton get1Button =
new
JButton("Get Memo 1");
45
get1Button.addActionListener(
this
);
46
buttonPanel.add(get1Button);
47
JButton get2Button =
new
JButton("Get Memo 2");
48
get2Button.addActionListener(
this
);
49
buttonPanel.add(get2Button);
50
add(buttonPanel, BorderLayout.SOUTH);
51
JPanel textPanel =
new
JPanel();
52
textPanel.setBackground(Color.BLUE);
53
memoDisplay =
new
JTextArea(LINES, CHAR_PER_LINE);
54
memoDisplay.setBackground(Color.WHITE);
55
JScrollPane scrolledText =
new
JScrollPane(memoDisplay);
56
scrolledText.setHorizontalScrollBarPolicy(
57
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
58
scrolledText.setVerticalScrollBarPolicy(
59
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
60
textPanel.add(scrolledText);
61
add(textPanel, BorderLayout.CENTER);
62
}
(continued)