SHOW:
|
|
- or go back to the newest paste.
1 | import java.awt.*; | |
2 | import javax.swing.*; | |
3 | ||
4 | public class TextAreaDemoB extends JFrame { | |
5 | //============================================== instance variables | |
6 | JTextArea _resultArea = new JTextArea(6, 20); | |
7 | ||
8 | //====================================================== constructor | |
9 | public TextAreaDemoB() { | |
10 | String[] words = {"my","text","area"}; | |
11 | ||
12 | for(String W : words) | |
13 | - | _resultArea.setText(W + "\n"); |
13 | + | _resultArea.append(W + "\n"); |
14 | JScrollPane scrollingArea = new JScrollPane(_resultArea); | |
15 | ||
16 | //... Get the content pane, set layout, add to center | |
17 | JPanel content = new JPanel(); | |
18 | content.setLayout(new BorderLayout()); | |
19 | content.add(scrollingArea, BorderLayout.CENTER); | |
20 | ||
21 | //... Set window characteristics. | |
22 | this.setContentPane(content); | |
23 | this.setTitle("TextAreaDemo B"); | |
24 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
25 | this.pack(); | |
26 | } | |
27 | ||
28 | //============================================================= main | |
29 | public static void main(String[] args) { | |
30 | JFrame win = new TextAreaDemoB(); | |
31 | win.setVisible(true); | |
32 | } | |
33 | } |