by Dinesh Thakur Category: Swing

A scrolling pane is a container that can be used to hold any component that can be scrolled. By default, the list and textarea component do not scroll automatically when number of items in the list or text area component go beyond the displayed area. So to make these components scroll, you must insert them into the scrollpane. After you create a scrollpane containing a component (list or textarea), the scrolling pane should be added to the container in place of that component. A scrolling pane can be created by instantiating the JScrollPane class.

import javax.swing.*;

import java.awt.*;
class JScrollPaneExample extends JFrame
     setLayout(new FlowLayout());
     String[] language = {"Cobol","Fortran","Pascal","C","C++","java","C#"};
     JLabel lblLanguage = new JLabel("Choose the Language");
     JList LstMonth = new JList(language);
     LstMonth.setVisibleRowCount (4);
     JScrollPane s = new JScrollPane(LstMonth,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  class JScrollPaneJavaExample
      public static void main(String[] args)
          JScrollPaneExample frame = new JScrollPaneExample();
          frame.setTitle("JScrollPane Java Example");

JScrollPane in Java Swing Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular 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.

Related Articles