package com.mindprod.example;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Insets;
import static java.lang.System.*;
/**
* demonstrate the use of javax.swing.JTextArea.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-01-01 initial version
* @since 2009-01-01
*/
public final class TestJTextArea
{
/**
* Debugging harness for a Frame
*
* @param args command line arguments are ignored.
*/
public static void main( String args[] )
{
SwingUtilities.invokeLater( new Runnable()
{
/**
* fire up a JFrame on the Swing thread
*/
public void run()
{
final JFrame jFrame = new JFrame();
final Container contentPane = jFrame.getContentPane();
final JTextArea jTextArea =
new JTextArea( "this is a TEST\n"
+ "of multiline." );
jTextArea.setBackground( Color.BLACK );
jTextArea.setForeground( Color.YELLOW );
jTextArea.setFont( new Font( "Dialog", Font.BOLD, 15 ) );
jTextArea.setMargin( new Insets( 4, 4, 4, 4 ) );
jTextArea.setLineWrap( true );
jTextArea.setWrapStyleWord( true );
jTextArea.setBorder( BorderFactory.createLoweredBevelBorder() );
jTextArea.setEnabled( true );
jTextArea.setEditable( true );
Document document = jTextArea.getDocument();
document.addDocumentListener( new DocumentListener()
{
/**
* Gives notification that an attribute or set of attributes
* changed.
* @param e the document event
*/
public void changedUpdate( DocumentEvent e )
{
out.println( "changed: " + jTextArea.getText() );
}
/**
* Gives notification that there was an insert into the
* document. The range given by the DocumentEvent bounds the
* freshly inserted region.
* @param e the document event
*/
public void insertUpdate( DocumentEvent e )
{
out.println( "inserted: " + jTextArea.getText() );
}
/**
* Gives notification that a portion of the document has
* been removed. The range is given in terms of what the
* view last saw (that is, before updating sticky
* positions).
* @param e the document event
*/
public void removeUpdate( DocumentEvent e )
{
out.println( "removed: " + jTextArea.getText() );
}
} );
contentPane.add( jTextArea );
jFrame.setSize( 100, 100 );
jFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
jFrame.validate();
jFrame.setVisible( true );
}
} );
}
}