/* * File: TextAreaTest.java * * Create an noneditable text area * * Copyright: Northeast Parallel Architectures Center * */ import java.awt.*; import javax.swing.*; public class TextAreaTest extends JApplet { // use the textarea to display some text private JTextArea verse; private Font f = new Font ("Monospaced", Font.BOLD, 18); public void init() { getContentPane().setLayout(new FlowLayout()); getContentPane().setBackground( Color.white ); String str = "Once upon a midnight dreary, while I pondered, weak and weary,\n" + "Over many a quaint and curious volume of forgotten lore,\n" + "While I nodded, nearly napping, suddenly there came a tapping,\n" + "As of some one gently rapping, rapping at my chamber door.\n" + "\"'Tis some visitor,\" I muttered, \"tapping at my chamber door-\n" + "Only this, and nothing more.\"\n\n" + "Ah, distinctly I remember it was in the bleak December,\n" + "And each separate dying ember wrought its ghost upon the floor.\n" + "Eagerly I wished the morrow;- vainly I had sought to borrow\n" + "From my books surcease of sorrow- sorrow for the lost Lenore-\n" + "For the rare and radiant maiden whom the angels name Lenore-\n" + "Nameless here for evermore."; // initial text, height in lines, width in characters, scrollbar visibility verse = new JTextArea( str, 8, 30 ); verse.setEditable( false ); verse.setFont(f); JScrollPane j=new JScrollPane(verse,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ); getContentPane().add(j); } }