Example ScrollBar Demo

    

The demo shows an ExampleVScrollBar and an ExampleHScrollBar whose values are drawn in the draw() method. A Checkbox is also included to show that the min and max values scrollbar values can be reversed to reverse the orientation of the bars.

The vertical scroll bar uses the labels option. The horizontal scroll bar uses the hashmark and value options.

This demo shows how to create a new scrollbar class by extending the Scroller class. Two new classes are created. They are both just 16 lines long. The general process is as follows:

  1. Write a class name statement that extends Scroller.
  2. Add any desired fields.
  3. Write a constructor statement including desired parameters.
  4. Call super(...) with the required 10 arguments.
  5. Create a new scroll button:
           scrollBtn = new ...
  6. Optional: create new up and down buttons:
           upBtn = new ...
           downBtn = new ...
  7. Call setScrollValues();     to complete the construction.
  8. Optional: call setValue(...);     to set the starting value of scroll button.

The example has separate constructors for horizontal and vertical scrollbars. It is possible to combine them by adding a parameter for the desired orientation (or otherwise determining the orientation) and using the select_(..., ..., ...) method to supply appropriate values for each case when the values differ.

The class and sketch code are in the file ExampleScrollBarDemo.pde. The Scroller code is in the file Dragger.pde

Return to the top of the page

Revised: 04/11/2014