001         package com.croftsoft.core.gui;
002    
003         import java.awt.*;
004         import java.awt.event.*;
005         import java.io.*;
006         import java.net.*;
007         import javax.swing.*;
008         import javax.swing.event.*;
009         import javax.swing.border.*;
010    
011         import com.croftsoft.core.lang.NullArgumentException;
012    
013         /*********************************************************************
014         * Creates a JPanel containing a scrollable JTextArea.
015         *
016         * @version
017         *   2001-09-21
018         * @since
019         *   2001-09-21
020         * @author
021         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
022         *********************************************************************/
023    
024         public final class  TextPanel
025           extends JPanel
026         //////////////////////////////////////////////////////////////////////
027         //////////////////////////////////////////////////////////////////////
028         {
029    
030         private final JTextArea  jTextArea;
031    
032         //////////////////////////////////////////////////////////////////////
033         //////////////////////////////////////////////////////////////////////
034    
035         /*********************************************************************
036         * Main constructor.
037         *
038         * @param  text
039         *
040         *   May be null.
041         *
042         * @param  panelBackgroundColor
043         *
044         *   May be null.
045         *********************************************************************/
046         public  TextPanel (
047           String  text,
048           Color   panelBackgroundColor )
049         //////////////////////////////////////////////////////////////////////
050         {
051           super ( new BorderLayout ( ), true ); // isDoubleBuffered
052    
053           if ( panelBackgroundColor != null )
054           {
055             setBackground ( panelBackgroundColor );
056           }
057    
058           jTextArea = new JTextArea ( );
059    
060           jTextArea.setEditable ( false );
061    
062           jTextArea.setLineWrap ( true );
063    
064           jTextArea.setWrapStyleWord ( true );
065    
066    // How can I set the border to 2 characters wide?
067    
068           jTextArea.setBorder ( new EmptyBorder ( 4, 4, 4, 4 ) );
069    
070           if ( text != null )
071           {
072             jTextArea.setText ( text );
073           }
074    
075           add ( new JScrollPane ( jTextArea ), BorderLayout.CENTER );
076         }
077    
078         /*********************************************************************
079         * Convenience constructor.
080         *
081         * <pre>
082         * this ( null, panelBackgroundColor );
083         * </pre>
084         *
085         * @param  panelBackgroundColor
086         *
087         *    May be null.
088         *********************************************************************/
089         public  TextPanel ( Color  panelBackgroundColor )
090         //////////////////////////////////////////////////////////////////////
091         {
092           this ( null, panelBackgroundColor );
093         }
094    
095         /*********************************************************************
096         * Convenience constructor.
097         *
098         * <pre>
099         * this ( null, null );
100         * </pre>
101         *********************************************************************/
102         public  TextPanel ( )
103         //////////////////////////////////////////////////////////////////////
104         {
105           this ( null, null );
106         }
107    
108         //////////////////////////////////////////////////////////////////////
109         //////////////////////////////////////////////////////////////////////
110    
111         public JTextArea  getJTextArea ( ) { return jTextArea; }
112    
113         public void  setText ( String  text )
114         //////////////////////////////////////////////////////////////////////
115         {
116           jTextArea.setText ( text );
117         }
118    
119         //////////////////////////////////////////////////////////////////////
120         //////////////////////////////////////////////////////////////////////
121         }