Java JScrollBar handle adjustment event
import java.awt.FlowLayout; import java.awt.event.AdjustmentEvent; import javax.swing.JFrame; import javax.swing.JScrollBar; public class Main extends JFrame { public Main() { JScrollBar sb1 = new JScrollBar(); getContentPane().setLayout(new FlowLayout()); getContentPane().add(sb1);//from w ww . j a v a 2 s.com sb1.addAdjustmentListener((AdjustmentEvent e) -> { if (!e.getValueIsAdjusting()) { // The logic for value changed goes here System.out.println(e.getValue()); } }); } public static void main(String[] args) { Main gui = new Main(); gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gui.setSize(400, 250); gui.setVisible(true); } }