3.10.9 - Scroll Bar - JdlScrollbar

John W. Campbell

3.10.9.1 Introduction

This class provides a slimline scroll bar object designed to match the general style of JdlView objects.

Class, fields, constructor and methods:

Class Details
Accessible Fields
Constructor
Operational Methods
Resource Methods
Standard Positioning and Sizing
Add/Remove Action Listener
Overriden Superclass Methods

3.10.9.2 Class Details

Package:
Jdl.JdlView;
Class name:
JdlScrollbar
Class definition:
public class JdlScrollbar
Extends:
JPanel
Implements:
MouseListener
MouseMotionListener
Actions:
An action event will be generated when the scrollbar has been moved and the mouse button released. If required action events may also be generated which track the scroll bar movement continuously. The associated object is one of the following strings:
"scroll gripped"
"scroll released"
"scroll moved"
"scroll -single n" (n= number of steps moved)
"scroll +single n" (n= number of steps moved)
"scroll -block n" (n= number of blocks moved)
"scroll +block n" (n= number of blocks moved)
"scrollbar motion"

3.10.9.3 Accessible Fields

The following accessible fields have been defined:

public final static int VERTICAL
Orientation: Vertical.
public final static int HORIZONTAL
Orientation: Horizontal.
static final long serialVersionUID
public final static int PREFERRED
Size Constraint: preferred size.
public final static int FREE
Size/Location Constraint: free.

3.10.9.4 Constructor

3.10.9.4.1 Introduction

A single constructor is available.

Constructor:

Standard constructor

3.10.9.4.2 Standard constructor

Constructs a scrollbar with a given length and orientation.

Constructor Definition:
public JdlScrollbar(int displen, int orient)
Parameters List:
displen
The length of the display area on the screen in pixels; this will be used as the overall length (long dimension) of the scroll bar object.
orient
The required orientation:
= 0, Vertical (May use VERTICAL)
= 1, Horizontal (May use HORIZONTAL)

3.10.9.5 Operational Methods

3.10.9.5.1 Introduction

This section contains the main methods used with normal operation of the object.

Methods:

Set values - setScrollbarValues
Get value - getScrollbarValue
Set increments - setScrollbarIncrements
At start - isScrollAtStart
At end - isScrollAtEnd

3.10.9.5.2 Set values - setScrollbarValues

This method sets the scrollbar values.

Method Definition:
public void setScrollbarValues (int min, int max, int val)
Parameters List:
min
The minimum value for the scrollbar range (default = 0).
max
The maximum value for the scrollbar range (default = 100) - must be greater than 'min'.
val
The currently required scrollbar value (default = 50) - must be within the range 'min' to 'max'. The scrollbar value resource changes as the scrollbar is moved. The range actually used is normally from min to (max - displen) i.e the length of the scrollable window (from start of the window to the start of the last displayable section of the window) unless a fixed length grip is used in which case the actual values are used.

This method sets the three resources to ensure consistency. Separate methods return each of the three values.

3.10.9.5.3 Get value - getScrollbarValue

This method returns the current scrollbar value.

Method Definition:
public int getScrollbarValue()
Parameters List:
none
Method Return:
Returns the current scrollbar value.

3.10.9.5.4 Set increments - setScrollbarIncrements

Set increments for scrolling when end button selected or empty track area selected.

Method Definition:
public void setScrollbarIncrements (int single, int block)
Parameters List:
single
The increment (same units as for setScrollbarValues) when an start or end button is selected. (start uses -ve of this value).
block
The increment (same units as for setScrollbarValues) when an start or end section of empty track is selected. (start uses -ve of this value).

3.10.9.5.5 At start - isScrollAtStart

This method returns a flag indicating whether or not the scroll grip is at the start position.

Method Definition:
public boolean isScrollAtStart()
Parameters List:
none
Method Return:
True if scrollbar at start, else false.

3.10.9.5.6 At end - isScrollAtEnd

This method returns a flag indicating whether or not the scroll grip is at the end position.

Method Definition:
public boolean isScrollAtEnd()
Parameters List:
none
Method Return:
True if scrollbar at end, else false.

3.10.9.6 Resource Methods

3.10.9.6.1 Introduction

This section has methods to set/get the resources associated with the object determining its appearance and mode of action.

Methods:

Set continuous monitor - setContinuousMonitor
Get continuous monitor - getContinuousMonitor
Set display length - setDisplayLength
Get display length - getDisplayLength
Set fixed length grip - setFixedGripLength
Get fixed grip width - getScrollbarWidth
Get maximum value - getScrollbarMaximum
Get minimum value - getScrollbarMinimum

3.10.9.6.2 Set continuous monitor - setContinuousMonitor

This method sets the continuous monitor resource.

Method Definition:
public void setContinuousMonitor(boolean flag)
Parameters List:
flag
Set to true for continuous monitoring of scrollbar value (via action events) as the scrollbar grip is dragged (default = true).

3.10.9.6.3 Get continuous monitor - getContinuousMonitor

This method returns the continuous monitor resource.

Method Definition:
public boolean getContinuousMonitor()
Parameters List:
none
Method Return:
Returns the current value of the continuous monitor resource flag.

3.10.9.6.4 Set display length - setDisplayLength

This method sets the display length - note, will be ignored if called while the grip is being dragged.

Method Definition:
public void setDisplayLength(int displen)
Parameters List:
displen
The display length in pixels

3.10.9.6.5 Get display length - getDisplayLength

This method returns the display length resource.

Method Definition:
public int getDisplayLength()
Parameters List:
none
Method Return:
Returns the display length resource.

3.10.9.6.6 Set fixed length grip - setFixedGripLength

This method sets a fixed length of grip - can be used if scrollbar is being used as a slider and the grip length thus does not relate directly to the display length and the slider maximum value. (default =0, means not used).

Method Definition:
public void setFixedGripLength(int len)
Parameters List:
none

3.10.9.6.7 Get fixed grip width - getScrollbarWidth

This method returns the (fixed) scrollbar 'width' (i.e its narrow dimension)

Method Definition:
public int getScrollbarWidth()
Parameters List:
none
Method Return:
Returns the scrollbar width.

3.10.9.6.8 Get maximum value - getScrollbarMaximum

This method returns the scrollbar maximum value resource.

Method Definition:
public int getScrollbarMaximum()
Parameters List:
none
Method Return:
Returns the scrollbar maximum value resource (note - set via setScrollbarValues)

3.10.9.6.9 Get minimum value - getScrollbarMinimum

This method returns the scrollbar minimum value resource.

Method Definition:
public int getScrollbarMinimum()
Parameters List:
none
Method Return:
Returns the scrollbar minimum value resource (note - set via setScrollbarValues)

3.10.9.7 Standard Positioning and Sizing

3.10.9.7.1 Introduction

This section contains the standard methods for positioning and sizing the object.

Methods:

Set position constraints - setLocationConstraints
Set size constraints - setSizeConstraints
Set minimum height - setMinimumHeight
Set minimum width - setMinimumWidth

3.10.9.7.2 Set position constraints - setLocationConstraints

Set constraints on the Jdl object positioning.

Method Definition:
public void setLocationConstraints (int constraint_x, int constraint_y)
Parameters List:
constraint_x
Constrain the Jdl Object 'x' position = the required Jdl Object 'x' position (overrides setLocation method) or FREE if the 'x' position may be set by the setLocation method and hence possibly by the layout manager.
constraint_y
Constrain the Jdl Object 'y' position = the required the Jdl Object 'y'position (overrides setLocation method) or FREE if the 'y' position may be set by the setLocation method and hence possibly by the layout manager.

3.10.9.7.3 Set size constraints - setSizeConstraints

Set constraints on the Jdl Object resizing permitted.

Method Definition:
public void setSizeConstraints (int constraint_w, int constraint_h)
Parameters List:
constraint_w
Constrain the Jdl Object width = the required Jdl Object width, or PREFERRED (default) if the width is to be calculated from the current resources, or FREE if the width may be resized to anything greater than the minimum width required.
constraint_h
Constrain the Jdl Object height = the required Jdl Object height, or PREFERRED (default) if the height is to be calculated from the current resources, or FREE if the height may be resized to anything greater than the minimum height required.

3.10.9.7.4 Set minimum height - setMinimumHeight

Set the minimum height resource.

Method Definition:
public void setMinimumHeight(int minh)
Parameters List:
minh
The minimum height required for the object (ignored if less than that required by the minimum layout) (default = 0).

3.10.9.7.5 Set minimum width - setMinimumWidth

Set the minimum width resource.

Method Definition:
public void setMinimumWidth(int minw)
Parameters List:
minh
The minimum width required for the object (ignored if less than that required by the minimum layout) (default = 0).

3.10.9.8 Add/Remove Action Listener

3.10.9.8.1 Introduction

This section has methods to add or remove an action listener.

Methods:

Add action listener - addActionListener
Remove action listener - removeActionListener

3.10.9.8.2 Add action listener - addActionListener

This adds the specified action listener to receive action events from this object.

Method Definition:
public void addActionListener(ActionListener listener)
Parameters List:
listener
The action listener to be added.

3.10.9.8.3 Remove action listener - removeActionListener

This removes the specified action listener so that it no longer receives action events from this object.

Method Definition:
public void removeActionListener(ActionListener listener)
Parameters List:
listener
The action listener to be removed.

3.10.9.9 Overriden Superclass Methods

3.10.9.9.1 Introduction

This section contains methods which override the corresponding superclass methods. These are basically standard for JdlView objects and comprise methods to set background and foreground colours and to get the minimum and preferred sizes for the object. (The paintComponent method is also over-ridden but is not normally called by the user).

Methods:

Set background - setBackground
Set background colours - setBackground
Set foreground - setForeground
Get minimum size - getMinimumSize
Get preferred size - getPreferredSize

3.10.9.9.2 Set background - setBackground

This method sets the background colour resource.

Method Definition:
public void setBackground (Color c)
Parameters List:
c
The color to become this object's background color.

3.10.9.9.3 Set background colours - setBackground

This method sets the background colour resource and brighter and darker shades of that colour (e.g. for 3-D frames).

Method Definition:
public void setBackground (Color c, Color brighter, Color darker)
Parameters List:
c
The background colour.
brighter
A brighter shade of the background colour.
darker
A darker shade of the background colour.

3.10.9.9.4 Set foreground - setForeground

This method sets the foreground colour resource.

Method Definition:
public void setForeground (Color c)
Parameters List:
c
The color to become this object's foreground color.

3.10.9.9.5 Get minimum size - getMinimumSize

This method returns the minimum size of the component.

Method Definition:
public Dimension getMinimumSize()
Parameters List:
none

3.10.9.9.6 Get preferred size - getPreferredSize

This method returns the preferred size of the component.

Method Definition:
public Dimension getPreferredSize()
Parameters List:
none

⇑ Up 3   ⇑ Up 2   ⇑ Up 1   ⇑ Top of this