Java tutorial
import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; import javax.swing.JFrame; import javax.swing.JScrollBar; import javax.swing.JScrollPane; import javax.swing.JTextArea; public class Main { public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); JTextArea b = new JTextArea(); b.setPreferredSize(new Dimension(600, 600)); JScrollPane pane = new JScrollPane(b); AdjustmentListener hListener = new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { System.out.println("Horizontal: "); dumpInfo(e); } }; JScrollBar hBar = pane.getHorizontalScrollBar(); hBar.addAdjustmentListener(hListener); AdjustmentListener vListener = new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { System.out.println("Vertical: "); dumpInfo(e); } }; JScrollBar vBar = pane.getVerticalScrollBar(); vBar.addAdjustmentListener(vListener); contentPane.add(pane, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); } private static void dumpInfo(AdjustmentEvent e) { System.out.println("getValueIsAdjusting: " + e.getValueIsAdjusting()); } }