The simplest of the bounded range components is the JScrollBar : JScrollBar « Swing « Java Tutorial






Handling Scrolling Events

The simplest of the bounded range components is the JScrollBar
import java.awt.BorderLayout;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;

import javax.swing.JFrame;
import javax.swing.JScrollBar;


public class ScrollBarSample {
  public static void main(String args[]) {
    AdjustmentListener adjustmentListener = new AdjustmentListener() {
      public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) {
        System.out.println("Adjusted: " + adjustmentEvent.getValue());
      }
    };
    JScrollBar oneJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
    oneJScrollBar.addAdjustmentListener(adjustmentListener);

    JFrame frame = new JFrame("ScrollBars R Us");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(oneJScrollBar, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}








14.48.JScrollBar
14.48.1.The simplest of the bounded range components is the JScrollBarThe simplest of the bounded range components is the JScrollBar
14.48.2.Listening to Scrolling Events with a ChangeListenerListening to Scrolling Events with a ChangeListener
14.48.3.JScrollBar and Adjustment event
14.48.4.Always display scrollbar
14.48.5.Customizing a JScrollBar Look and Feel