What is JScrollBar - Java Swing

Java examples for Swing:JScrollBar

Introduction

A JScrollBar is made up of four parts: two arrow buttons with one at each end, a knob or thumb, and a track.

Create a JScrollBar with all default properties. Its orientation will be vertical, current value 0, extent 10, minimum 0, and maximum 100

JScrollBar sb1 = new JScrollBar();

Create a horizontal JScrollBar with default values

JScrollBar sb2 = new JScrollBar(JScrollBar.HORIZONTAL);

Create a horizontal JScrollBar with a current value of 50, extent 15, minimum 1 and maximum 150

JScrollBar sb3 = new JScrollBar(JScrollBar.HORIZONTAL, 50, 15, 1, 150);

The current value of a JScrollBar can be set only between its minimum and maximum - extent value.

Handle AdjustmentListener for a JScrollBar.

myScrollBar.addAdjustmentListener((AdjustmentEvent e) -> {
        if (!e.getValueIsAdjusting()) {
                // The logic for value changed goes here
        }
});

Related Tutorials