Turn Desktop View Off
You are here:   HomeJava ProgrammingSwingExample JScrollPane in Java Swing
by Dinesh Thakur Category: Swing

A scroll pane is a container that represents a small area to view other component. If the component is larger than the visible area, scroll pane provides horizontal and/or vertical scroll bars automatically for scrolling the components through the pane. A scroll pane is an object of the JScrollPane class which extends JComponent.

Some of the constructors defined by JScrollPane class are as follows.

JSrollPane ()

JScrollPane(Component component)

JScrollPane(int ver, int hor)

JScrollPane(Component component, int ver, int hor)


component is the component to be added to the scroll pane

ver and hor specify the policies to display the vertical and horizontal scroll bar, respectively. Some of the standard policies are:


Note: JScrollPane is a lightweight container.

import javax.swing.*;
import java.awt.*;
public class JavaExampleJScrollPane extends JFrame
      private JPanel Pnl = new JPanel();
      private JScrollPane Scrl = new JScrollPane(Pnl,
      private JLabel Lbl = new JLabel("JScrollPane in Java Swing Example");
      private Font font = new Font("Arial", Font.PLAIN, 20);
      private Container cntnr;
      public JavaExampleJScrollPane()
              super("JScrollPane in Java Swing Example");
              cntnr = getContentPane();
              public static void main(String[] args)
                     final int WIDTH = 180;
                     final int HEIGHT = 100;
                     JavaExampleJScrollPane Scroll = new JavaExampleJScrollPane();
Example JScrollPane in Java Swing

Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.

What's New and Popular

Popular Article