how-to

Events

How to check and write current scrollbar position

java.awt.event.AdjustmentEvent is emitted when user is doing scrolling in the component. For writing new javax.swing.JScrollBar value use this code:

/* -- add listener */
        
jScrollBar1.addAdjustmentListener( new java.awt.event.AdjustmentListener() {
  public void adjustmentValueChanged( java.awt.event.AdjustmentEvent evt ) {
    jScrollBar1AdjustmentValueChanged( evt );
  }
});
...
...
...
/* -- code */

private void jScrollBar1AdjustmentValueChanged( java.awt.event.AdjustmentEvent evt ) {
  if ( evt.getAdjustable() == jScrollBar1 )
    lblScroll.setText( String.valueOf( evt.getValue() ) );
}

New scrollbar value is displayed.