Java JScrollPane Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Java JScrollPane is a component in the Java Swing library that provides a scrollable view of another component, usually a JPanel or a JTextArea. it provides a scrolling functionality to the display for which the size changes dynamically. It is useful to display the content which exceeds the visible area of the window. In this article, we are going to see some constructors, methods, and examples of JScrollPane. Constructor of JScrollPaneConstructors Descriptions JScrollPane() It is a default constructor that creates an empty JScrollPane. JScrollPane(Component comp) This constructor creates a JScrollPane with the specified view component as the scrollable content. JScrollPane(int vertical, int horizontal) This constructor creates an empty JScrollPane with the specified vertical and horizontal scrollbar. JScrollPane(LayoutManager layout) This constructor creates a JScrollPane with the specified layout manager. Methods of JScrollPaneMethods Description void setVerticalScrollBarPolicy(int vertical) Sets the vertical scrollbar policy void setHorizontalScrollBarPolicy(int horizontal) Sets the horizontal scrollbar policy void setColumnHeaderView(Component comp) sets the column header for the JScrollPane void setRowHeaderView(Component comp) sets the rowheader for the JScrollPane setCorner(String key, Component corner) It is used to set a component to be displayed in one of the corners of the scroll pane Component getCorner(String key) It is used to retrieve the component that has been previously set in one of the corners of the scroll pane using the setCorner method void setViewportView(Component comp) It is used to set the component that will be displayed in the viewport of the scroll pane Following are the programs to implement JScrollPane1. Java Program to demonstrate simple JscrollPaneBelow is the implementation of the above topic: Java // Java Program to demonstrate // Simple JscrollPane import javax.swing.*; import java.awt.*; // Driver Class public class SimpleJScrollPaneExample { // main function public static void main(String[] args) { JFrame frame = new JFrame("Simple JScrollPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 200); // Create a JPanel to hold a list of labels. JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // Add a large number of labels to the panel. for (int i = 1; i <= 50; i++) { JLabel label = new JLabel("Label " + i); panel.add(label); } // Create a JScrollPane and set the panel as its viewport. JScrollPane scrollPane = new JScrollPane(panel); // Add the JScrollPane to the frame. frame.add(scrollPane); frame.setVisible(true); } } Output: 2. Java Program to Implementing a JTextArea to JScrollPaneBelow is the implementation of the above topic: Java // Java Program to Implementing // JTextArea to JScrollPane import javax.swing.*; // Driver Class public class JTextAreaExample { // main function public static void main(String[] args) { JFrame frame = new JFrame("Java JTextArea in JScrollPane"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 300); // Creating an JTextArea with 10 rows, 30 columns JTextArea textArea = new JTextArea(10, 30); // Creating an JScrollPane JScrollPane scrollPane = new JScrollPane(textArea); frame.add(scrollPane); frame.setVisible(true); } } Output: Comment More infoAdvertise with us Next Article Java JRootPane C chinmaya121221 Follow Improve Article Tags : Java Geeks Premier League java-swing Geeks Premier League 2023 Practice Tags : Java Similar Reads Java JScrollBar Java's Swing library provides various GUI components for creating graphical user interfaces. Among these components, is the JScrollBar class, which allows users to scroll through the content of a component, such as a JScrollPane. In Java JScrollBar is a part of javax.swing package. Constructor of JS 4 min read Java JRootPane In Java Swing, JRootPane is a fundamental component that serves as the root container for creating complex user interfaces. It encapsulates the core functionality of a top-level window, like JFrame, and provides a structure for organizing the content within a GUI application. In Java JRootPane is a 3 min read Java JDesktopPane Java JDesktopPane is a part of the Swing library that helps Java Developers to make desktop-like applications, It allows the developers to manage and organize child frames within a parent frame. In this article, we are going to see some constructors, methods, fields, and some examples of JDesktopPan 4 min read Java AWT Scrollbar Java AWT (Abstract Window Toolkit) is a collection of libraries for developing responsive and user-friendly interfaces in Java Applications. The Scrollbar is a component that allows us to see an unknown number of rows and columns. Java AWT ScrollbarThe 'Scrollbar' class is a part of the 'java.awt' p 6 min read Java JEditorPane A JEditorPane is a component in Java Swing that provides a simple way to display and edit HTML and RTF (Rich Text Format) content. It is a versatile component that allows you to display styled text, links, and images, making it useful for creating simple web browsers, rich-text editors, and content 3 min read Java JOptionPane In Java, JOptionPane is a part of the Java Swing library. It helps us to create dialog boxes such as message dialogs, conformation dialogs, input dialogs, and options dialogs In this article, we are going to explore some constructors, methods, and some examples of JOptionPane. Constructors of JOptio 5 min read Like