The ScrollBar is one of three extensions of the very general abstract class Scroller. See SimpleScrollBar and Slider for the other scrollable devices. To show some of the possibilities, this demo shows several ScrollBars. They differ in orientation and the options used. The table below shows which options were used with which ScrollBar. Unfortunately dragging the scroll button on a ScrollBar probably will not work on touch screens. While the operating system typically passes taps on to the application as clicks, it captures the swiping actions and does not let applications see them without using special techniques which unfortunately are often system dependent. Consequently, there is an option to have ScrollBars to respond to clicks (and hence taps). The horizontal green bar uses this option, In addition, the width of the scroll bar was set to 1. (The resulting scroll "line" can be dragged although it is difficult to set the cursor on the line.) |
The sketch code is in the file ScrollBarDemo.pde | The ScrollBar code is in the file Dragger.pde |
ScrollBar | Options |
---|---|
Horizontal Red | It uses the very general 10 parameter constructor and sets the button color to red. It uses the showLabels(64) and showHashmarks(32) in the setup method. It also uses displayOneLabel(255) in the draw method in order to provide the "255" label. |
Horizontal Green | It uses the simpler 6 parameter constructor and the showValue() in the setup method. Also, setProcessClicks(true) means the bar will respond to clicks. setSizes(1) reduces the button to a line. |
Horizontal Blue | The simpler constructor specifies the max value 0 and min value 255 to reverse the scroll bar. It uses the showLabels(64) in the setup method. It also uses displayOneLabel(255) in the draw method in order to provide the "255" label. |
Vertical Red | It uses the simpler constructor and no options. This is the default constructor. |
Vertical Green | It uses the simpler constructor and showLabels(64) and showHashmarks(32) in the setup method. That method also specifies that the scroll button will have shades of green (setButtonFillColors(#00FF00, #00CC00)). It also uses displayOneLabel(255) in the draw method in order to provide the "255" label. |
Vertical Blue | It uses the simpler constructor. The minVal is set to 255 and the maxVal to 0 to reverse the direction of the bar. The setup method uses showHashmarks(32), showLabels(255) which draws labels at 0 and 255, and showValue(). Also, when this bar is dragged the code in the mousePressed() method sets the dragger's outside limit to 20 which means drags will terminate if the mouse is moved more than 20 pixels outside a ScrollBar. This setting applies to all the ScrollBars until it is changed. (The default is 100 pixels.) |
It only takes one Dragger object to handle all the ScrollBars because only one dragging operation can occur at a time..
class ScrollBar
extends Scroller
which extends ClickablePanel
which extends Clickable
The ScrollBar class creates a scroll bar with many options. The bar can be either vertical or horizontal. It is includes a draggable scroll button and has up/right and down/left buttons. The Scroller class provides labeling and other options. See the ScrollerDemo for a description of those options. There are two constructors.
** ScrollBar(boolean vert, Int leftX, int topY, int theWidth, int theHeight, int btnSize, String theLabel, color stdColor, color btnFillColor, float minValue, float maxValue) - Most general constructor for ScrollBar. Its orientation can be either vertical or horizontal. It includes buttons at either end that move the scroll button by about 10% of the length of the scroll bar. Parameters: boolean vert: True for vertical orientation, false for horizontal orientation. int leftX, int topY: Location of ScrollBar panel. int theWidth, int theHeight: The size of the ScrollBar. int btnSize: Size (height or width depending on ScrollBar's orientation) of scroll button. String: theLabel: The label for the ScrollBar. It is not displayed. color stdColor, color btnFillColor:The color of the bar and the color of the buttons. float minValue: Value corresponding to the bottom/left end of the panel. float maxValue: Value corresponding to the top/right end of the panel. minValue > maxValue is OK and just reverses the orientation of the bar. |
** ScrollBar(boolean vert, int leftX, int topY, int theSize, float minValue, float maxValue) - Simplified constructor for ScrollBar. Its orientation can be either vertical or horizontal. It includes buttons at either end that move the scroll button by about 10% of the length of the scroll bar. Parameters: boolean vert: True for vertical orientation, false for horizontal orientation. int leftX, int topY: Location of ScrollBar panel. int theSize: Length (height or width depending on orientation) of ScrollBar panel. float minValue: Value corresponding to the bottom/left end of the panel. float maxValue: Value corresponding to the top/right end of the panel. minValue > maxValue is OK and just reverses the orientation of the bar. |
Method use codes:
** This constructor or method is designed to be called in the user sketch.
* This method is normally not called in the user's sketch unless the Clickable item was not been included in a ClickableGroup. ClickableGroup automatically uses the method as needed. Exception: This method may be needed if the user is extending Clickable with a new class.
# This constructor or method is rarely used in the user program. In Java, it would probably marked "private". Clickable, ScrollBar, and some other abstract constructors would never be called directly by the user sketch because they do nothing useful unless the user is extending a class.
Inherited from Scroller
Fields
BUTTON_SIZE,
biggerVal,
canBeDragged,
circleAdjust
downBtn,
hashShow,
hashSpacing,
hashStart,
labelsShow,
labelsSpacing,
labelsStart,
maxVal,
minVal,
scrollBtn,
scrollBtnBorderColor,
scrollBtnFillColor,
scrollBtnPos,
scrollBtnSize,
scrollLength,
scrollMin,
smallerVal,
upBtn,
upDownBtnSize,
upDownDivisor,
val,
valRange,
valueShow,
vertical
Constructors
Scroller
Methods
adjustForCircleScrollBtn,
calcMinMaxRelatedValues,
checkForClick,
calcLoc,
calcValue,
display,
displayBtnLine,
displayHashMarks,
displayLabels,
displayOneLabel,
displayValue,
getButtonPos,
getMaxValue,
getMinValue,
getValue,
hasBeenClicked,
isOver,
moved,
readyForDrag,
setBarColors,
setButtonBorderColor,
setButtonFillColors,
setEnabled,
setMaxValue,
setMinValue,
setScrollable,
setScrollBtnPos
setScrollValues,
setSizes,
setValue,
setVisible,
showHashmarks,
showHashmarks,
showLabels,
showLabels,
showValue
Inherited from ClickablePanel
Fields
clickX,
clickY,
invisible,
wholeSkectch
Constructors
ClickablePanel, ClickablePanel, ClickablePanel
Methods
adjustPanel,
checkForClick,
display,
drawOnPanel,
getClickX,
getClickY,
getPanelX,
getPanelY,
isOver,
setClickX,
setClickY,
setColor
Inherited from Clickable
Fields
NOTHING_CLICKED,
COMBO_BUTTON,
DISABLED_COLOR,
borderColor,
c,
clicked,
clickedItemNum,
colorState,
enabled,
h,
label,
over,
overC,
scrollable,
selected,
selectedItemNum,
visible,
w,
x,
y
Constructors
Clickable
Methods
checkForClick,
display,
doNotSelect,
getClickedItemNum,
getColorState,
getH,
getItem,
getLabel,
getSelected,
getSelectedItem,
getSelectedItemLabel,
getSelectedItemNum,
getW,
getX,
getY,
hasBeenClicked,
hideSomething,
isOver,
setBorderColor,
setColorState,
setH,
setLabel,
setScrollable,
setSelected,
setSelectedItemNum,
setEnabled,
setVisible,
setW,
setX,
setY,
sX,
sY
Revised: 04/11/2014