// components/textarea/TextAreaDemo.java
// Purpose: Illustrate JTextArea, JScrollPane, BorderFactory, ...
// Author: Fred Swartz
// Date : 2000-04-26, ... 2004-11-03
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class TextAreaDemo extends JFrame {
//============================================== instance variables
JTextArea m_resultArea = new JTextArea(6, 30);
//====================================================== constructor
public TextAreaDemo() {
//... Set initial text, scrolling, and border.
m_resultArea.setText("Enter more text to see scrollbars");
JScrollPane scrollingArea = new JScrollPane(m_resultArea);
scrollingArea.setBorder(BorderFactory.createEmptyBorder(10,5,10,5));
// Get the content pane, set layout, add to center
Container content = this.getContentPane();
content.setLayout(new BorderLayout());
content.add(scrollingArea, BorderLayout.CENTER);
this.pack();
}
//============================================================= main
public static void main(String[] args) {
JFrame win = new TextAreaDemo();
win.setTitle("TextAreaDemo");
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
}