VOOZH about

URL: https://www.geeksforgeeks.org/java/java-jscrollbar/

⇱ Java JScrollBar - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java JScrollBar

Last Updated : 28 Apr, 2025

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 JScrollBar

1. This is the default constructor that creates a horizontal scrollbar with the default values. Its default orientation is JScrollBar (HORIZONTAL).

JScrollBar()

2. This constructor creates a scrollbar with the specified orientation. The orientation parameter can be one of the following constants: JScrollBar.HORIZONTAL, JScrollBar.VERTICAL

JScrollBar(int orientation)

3. This constructor creates a scrollbar with specified orientation, value, extent, minimum and maximum.

JScrollBar(int orientation, int value, int extent, int min, int max)

Some Methods of the JScrollBar

Methods of the JScrollBar are mentioned below:

  1. setValue(int value) : Sets the current value of the scrollbar to a specified value.
  2. getValue() : Retrieves the current value of the scrollbar, which indicates the current position of the thumb.
  3. setMinimum(int minimum) : Sets the minimum value of the scrollbar, defining the lower boundary of the range.
  4. getMinimum() : Returns the minimum value, allowing you to retrieve the lower boundary of the range.
  5. setMaximum(int maximum) : Sets the maximum value of the scrollbar, defining the upper boundary of the range.
  6. getMaximum() : Retrieves the maximum value, indicating the upper boundary of the range.

Following are the programs to implement JScrollBar

1. Java Program to Implement a Vertical ScrollBar

Output :

👁 2

Another Screenshot with Printed Data

👁 Vertical ScreenShot using JScrollBar

2. Java Program to Implement a Horizontal ScrollBar

Below is the implementation of the above mentioned:

Output : (Horizontal ScollBar)

👁 3

Extended ScrollBar:

👁 Horizontal Scrollbar using JScollBar

3. Java Program to Implement setMinimum() ,setMaximum() ,setValue() ,getValue() in JScrollBar

Output: (Setting Value According to ScrollBar)

👁 Setting Value According to ScrollBar

Output Showing the value 90:

👁 Setting Value According to ScrollBar value is 90

Comment