Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java Program to add scroll bars to JTextArea using JScrollPane

  1. #1
    Senior Member
    Join Date
    May 2008
    Posts
    19
    Thanks
    0
    Thanked 9 Times in 4 Posts

    Default Java Program to add scroll bars to JTextArea using JScrollPane

    With this code you can add scrolling capabilities to a JTextArea using JScrollPane.

    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
     
    public class ScrollingTextArea extends JFrame {
     
    	JTextArea txt = new JTextArea();
    	JScrollPane scrolltxt = new JScrollPane(txt);
     
    	public ScrollingTextArea() {
     
    		setLayout(null);
     
    		scrolltxt.setBounds(3, 3, 300, 200);
    		add(scrolltxt);		
    	}
     
     
    	public static void main(String[] args) {
     
    		ScrollingTextArea sta = new ScrollingTextArea();
    		sta.setSize(313,233);
    		sta.setTitle("Scrolling JTextArea with JScrollPane");
    		sta.show();		
    	}
     
    }

    The compiled code will create this:



    The scroll bars come into action when the text inside the JTextArea goes beyond its boundaries.


  2. The Following User Says Thank You to Flash For This Useful Post:

    javapenguin (December 7th, 2010)


  3. #2
    Junior Member
    Join Date
    May 2009
    Posts
    25
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: How to Add scroll bars to JTextArea using JScrollPane

    Nice, I didn't know how to do this before ^^

Similar Threads

  1. How to Change JTextArea font, font size and color
    By Flash in forum Java Swing Tutorials
    Replies: 7
    Last Post: January 14th, 2012, 10:47 PM