Java Swing JScrollpane JTextArea

w‮ttual.ww‬uri.com
Java Swing JScrollpane JTextArea
/**
 * @author lautturi.com 
 * Java example: jscrollpane example in java swing
 */

import java.util.*;

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Lautturi {

	public static void main(String[] args) {
		
    	JFrame frame = new JFrame("Test JScrollPane");
        frame.setDefaultCloseOperation(frame.DISPOSE_ON_CLOSE);
        frame.setSize(500, 500);
        frame.setLayout(null);
        
        JTextArea textArea1 = new JTextArea("java swing example jscrollpane textarea  java swing example jscrollpane "
        		+ "textarea java swing example jscrollpane textarea java swing example jscrollpane textarea ");
        textArea1.setLineWrap(true);
    	textArea1.setWrapStyleWord(true);
    	textArea1.setFocusable(false);
    	
    	// JScrollPane direct in JFrame
        JScrollPane scroll1 = new JScrollPane();		// Activate JScrollPane
        scroll1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); // set verticla
        //scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 	// or, and also in Horizontal
        //scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); 		// or, and also in Horizontal
        scroll1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 	// set horizontal
        scroll1.setBounds(20, 20, 100, 100); // set Bounds if add to a JPanel
    	scroll1.getViewport().add(textArea1); // Set textArea to JScrollPane by add to a JPanel too
    	

        frame.add(scroll1); 	 
        frame.setVisible(true);
	}
}
Created Time:2017-10-02 18:04:40  Author:lautturi