Class declaration
Following is the declaration for java.awt.Scrollbar class:
public class Scrollbar extends Component implements Adjustable, Accessible
Fields of Scrollbar Class
Following are the fields for java.awt.Image class:
static int HORIZONTAL --A constant that indicates a horizontal scroll bar.
static int VERTICAL --A constant that indicates a vertical scroll bar.
Now, let’s see AWT List Class Constructors.
Constructors of AWT Scrollbar

- orientation is specifying whether the scrollbar will be horizontal or vertical.
- Value is specifying the starting position of the knob of the Scrollbar on its track.
- Minimum is specifying the minimum width of the track on which the Scrollbar is moving.
- Maximum is specifying the maximum width of the track on which the Scrollbar is moving.
Methods of AWT Scrollbar
To perform the operations on the scrollbar, we have so many methods. Some of the important and most used methods are:

Java AWT Scrollbar Example
In the following example, we create a scrollbar using the Scrollbar () and add it to the Frame. This is a very simple example where we are just creating a frame and a scrollbar, and then we have added the Scrollbar to the Frame, and then we are setting the size, visibility, and layout of the Frame.
Example 1
// importing awt package
import java.awt.*;
public class ScrollbarExample1 {
// class constructor
ScrollbarExample1() {
// creating a frame
Frame f = new Frame("Scrollbar Example");
// creating a scroll bar
Scrollbar s = new Scrollbar();
// setting the position of scroll bar
s.setBounds (100, 100, 50, 100);
// adding scroll bar to the frame
f.add(s);
// setting size, layout and visibility of frame
f.setSize(400, 400);
f.setLayout(null);
f.setVisible(true);
}
// main method
public static void main(String args[]) {
new ScrollbarExample1();
}
}

You can also try this code with Online Java Compiler
Run Code
Output:

Try and compile it by yourself on java online compiler.
Example 2
import java.awt.*;
import java.awt.event.*;
public class ScrollbarExample2 {
// class constructor
ScrollbarExample2() {
// creating a Frame with a title
Frame frame = new Frame("Example of Scrollbar");
// creating a final object of Label
final Label label = new Label();
label.setAlignment(Label.CENTER);
label.setSize(450, 150);
// creating a final object of Scrollbar class
final Scrollbar temp = new Scrollbar();
// setting the position of scroll bar
temp.setBounds(100, 100, 50, 100);
// adding Scrollbar and Label to the Frame
frame.add(s);
frame.add(label);
frame.setSize(400, 400);
frame.setLayout(null);
frame.setVisible(true);
// adding AdjustmentListener to the scrollbar object
temp.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
label.setText("Vertical Scrollbar value is:"+ temp.getValue());
}
});
}
// main method
public static void main(String args[]){
new ScrollbarExample2();
}
}

You can also try this code with Online Java Compiler
Run Code
Output:

In this example, firstly, we have created a Scrollbar and added it to the Frame. We have used the addAdjustmentListener() method of the Scrollbar class, which receives the instances of the AdjustmentListener() method of the Scrollbar class, and eventually, we display it in the form of a label.
Also read, Introduction to Java and Hashcode Method in Java
Frequently Asked Questions
What is AWT?
It stands for Abstract Window Toolkit. It is an API that Java programmers use to create GUI(Graphical User Interface) objects such as scroll bars, windows, and buttons.
Do we have more methods for the AWT scrollbar?
Yes, we have more methods like paramString(), processAdjustmentEvent (AdjustmentEvent e), processEvent(AWTEvent e), removeAdjustmentListener (AdjustmentListener l), setBlockIncrement(int v), setOrientation (int orientation), setUnitIncrement(int v) and many more but in this article, we have just discussed important and most used ones.
Which library package needs to be imported to use awt Scrollbar?
We need to import class import java.awt.Scrollbar;
Conclusion
In this article, we have discussed the AWT List through different examples. We also discussed the constructors and methods of the AWT List.
Enhance your skills in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and more with our Coding Ninjas Studio Guided Path. If you want to sharpen your coding skills for the test, check out the mock test series and enter the contests on Coding Ninjas Studio! If you are just a beginner and want to know what questions big giants like Amazon, Microsoft, and Uber ask, check the problems, interview experiences, and interview bundle for placement preparations.
You may consider our paid courses curated by experts to give your career an edge over others!
Do Upvote and Happy Learning!