Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Example Java Swing Create a Scroll Pane Container in Java

Related Tutorials


 
 

Share on Google+Share on Google+

Create a Scroll Pane Container in Java

Advertisement
In this section, you will learn how to create a scroll pane container in Java Swing.

Create a Scroll Pane Container in Java

     

In this section, you will learn how to create a scroll pane container in Java Swing. When you simply create a Text Area and putting text in the that then the size of the text area is increased according to the length of the text. But you can fix the size of the text area through adding the JScrollPane component of Java Swing. Following is the screen shot for the result of the given program:

Swing Scroll Bar Component with Text Area

This program shows a scroll pane for the given text area. The following methods and APIs used in the program for creating the JScrollPane container.

JScrollPane(Component view): 
This is the constructor of JScrollPane Class. It extends from the JComponent. This constructor uses to create a JScrollPane . This JScrollPane displays the horizontal and vertical scroll bar. It takes the components for which the scroll pane has to be set.

Here is the code of program:

import javax.swing.*;

public class JScrollContainer{
public static void main(String[] args) {
String st = "Math_calculs_coordinate\n" 
"Computer_Operator_Programer\n" 
"Physics_Laboratry\n"
"Chemestru\n" 
"Biology" 
"Civics\n" +"History" 
"Hindi\n" "English\n" 
"Tally" "Coordinate\n"
"Trigonometry" "ram is a good boy\n" 
"He has four cars and two computers.";
JFrame frame = new JFrame("Creating a JScrollPane Container");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JTextArea area = new JTextArea(st,5,6);
JScrollPane spane = new JScrollPane(area);
panel.add(spane);
frame.add(panel);
frame.setSize(400,400);
frame.setVisible(true);
  }
}

Download this example

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 14, 2007

Related Tutorials

Discuss: Create a Scroll Pane Container in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
james
June 1, 2012
not working

im trying to add a scrollpane to a texfield but it doesn't show up. i've copied the same structure as the example but it is not appearing. any ideas on why?
DMCA.com