Posted by : Unknown Thursday, 18 June 2015

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class TextAreaDemo extends JPanel 
{
    public static void main(String[] args) 
    {
        JFrame window = new JFrame("Slider Demo");
        TextAreaDemo content = new TextAreaDemo();
        window.setContentPane(content);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setLocation(120,70);
        window.setSize(400,250);
        window.setVisible(true);
    }
    public TextAreaDemo() 
    {
       
        String text = "So, naturalists observe, a flea\n"
            + "Has smaller fleas that on him prey;\n"
            + "And these have smaller still to bite 'em;\n"
            + "And so proceed ad infinitum.\n\n"
            + "                              --Jonathan Swift";
       
        JTextArea textArea = new JTextArea();
        JScrollPane scrollPane = new JScrollPane(textArea);
       
        textArea.setText(text);
        textArea.setFont( new Font("Serif", Font.PLAIN, 24 ));
        textArea.setMargin( new Insets(7,7,7,7) );
       
        setLayout(new BorderLayout());
        setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        add(scrollPane, BorderLayout.CENTER);       
    }
}

Output:

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Translate

Popular Post

Total Pageviews

Blog Archive

- Copyright © Learning Java Program - Powered by Blogger -