Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

Create a Scroll Pane Container in Java

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

                         

» View all related tutorials
Related Tags: c com diff vi value return opera id show if example unc values exam mode ws xor sh bot e

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.