import javax.swing.*; import java.awt.*; public class TextBox { JTextArea box; JPanel panel; public TextBox() { this.box = new JTextArea( 8, 33 ); this.panel = new JPanel(); this.setup( "Text" ); } public TextBox( String title ) { this.box = new JTextArea( 8, 33 ); this.panel = new JPanel(); this.setup( title ); } private void setup( String s ) { FlowLayout arranger = new FlowLayout(); this.panel.setLayout( arranger ); this.panel.setPreferredSize( new Dimension( 450, 185 ) ); JScrollPane pane = new JScrollPane( this.box, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS ); JLabel title = new JLabel( s ); this.panel.add( title ); this.panel.add( pane ); box.setLineWrap( true ); box.setWrapStyleWord( true ); } public String getText() { String text = this.box.getText(); return text; } public void setText( String s ) { this.box.setText( s ); } public void setColor( Color c ) { this.box.setBackground( c ); this.panel.setBackground( c ); } public void addTo( Container c ) { c.add( this.panel ); } }