Class UIScroll
public class UIScroll extends UIPanel implements IUIScroll,
IUIPosition
{
// Fields
public static final int NOHIDE;
public static final int NOKEY;
public static final int NONPROPORTIONAL;
public static final int NOSHOW;
public static final int PAGE_DOWN;
public static final int PAGE_UP;
public static final int THICK;
public static final int THUMB;
public static final int VERTICAL;
// Constructors
public UIScroll();
public UIScroll(int style);
public UIScroll(int style, int min, int max, int page, int line,
int pos);
// Methods
public boolean action(Event e, Object o);
public IUIComponent add(int index, IUIComponent comp);
public synchronized void addAdjustmentListener(
IUIAdjustmentListener l);
public IUIComponent getLayoutComponent(int index);
public Dimension getMinimumSize();
public Point getPosition();
public Dimension getPreferredSize();
public int getRoleCode();
public int getScrollLine();
public int getScrollMax();
public int getScrollMin();
public int getScrollPage();
public int getScrollPos();
public int getStyle();
public int getXPosition();
public int getYPosition();
public boolean isKeyable();
public boolean isScrollable();
public void layout();
public boolean mouseDrag(Event e, int x, int y);
protected void processAdjustmentEvent(UIAdjustmentEvent e);
protected void processEvent(UIEvent e);
public synchronized void removeAdjustmentListener(
IUIAdjustmentListener l);
public int scrollEnd();
public int scrollHome();
public int scrollLineDown();
public int scrollLineUp();
public int scrollPageDown();
public int scrollPageUp();
public void setPosition(Point pt);
public void setPosition(int x, int y);
public int setScrollInfo(int min, int max, int page, int line,
int pos, boolean notify);
public int setScrollInfo(int min, int max, int page, int line,
int pos);
public void setScrollLine(int line);
public int setScrollLine(int line, boolean notify);
public void setScrollMax(int max);
public void setScrollMin(int min);
public void setScrollPage(int page);
public int setScrollPage(int page, boolean notify);
public void setScrollPos(int pos);
public int setScrollPos(int pos, boolean notify);
public int setScrollRange(int min, int max);
public void setStyle(int style);
public void setXPosition(int x);
public void setYPosition(int y);
}
This class implements a scroll track control. UIScroll defines the following five scroll track styles:
The following example shows how to construct a scroll track control using the defined styles.
// Construct a vertical scroll track that is always visible.
UIScroll sc1 = new UIScroll(UIScroll.VERTICAL | UIScroll.NOHIDE);
// Add sc1 to the container.
add(sc1);
In addition to setting styles, you can initialize the scroll track control's scroll information by specifying range, page, line, and current position values. The range indicates the possible number of scroll positions associated with the control. The page and line values define increments for adjusting the current position. The following example shows how to construct a scroll track control with specified scroll information.
// Construct a vertical scroll track that is always visible.
// Define its range to be 0 to 100, with a page of 4, a line
// of 2, and an initial position of 50.
UIScroll sc2 = new UIScroll(UIScroll.VERTICAL | UIScroll.NOHIDE,
0, 100, 4, 2, 50);
// Add sc2 to the container.
add(sc2);
UIScroll manages three components that allow the user to move the scroll track control's current position. Each component is identified by a layout index, as defined in the following table.
Layout Index
|
Component
|
THUMB
|
The component used to indicate the current position of the scroll track control (by default, a UIScrollThumb object). When the THUMB component is dragged with the mouse, the current position is moved in increments or decrements of one scroll position.
|
PAGE_UP
|
The track area above or to the left of the thumb component (by default, a UIRepeatButton object). When the PAGE_UP component is pressed with the mouse, the current position is moved in decrements of one line less than a page.
|
PAGE_DOWN
|
The track area below or to the right of the thumb component (by default, a UIRepeatButton object). When the PAGE_DOWN component is pressed with the mouse, the current position is moved in increments of one line less than a page.
|
UIScrollBar extends UIScroll to implement a scroll bar control. In addition to the three components defined by UIScroll, UIScrollBar adds LINE_UP and LINE_DOWN components to the ends of the scroll track. For a description of these components, see the UIScrollBar overview. Other classes that extend UIScroll include UISlider and UISpinner.
UIComponent
|
+--UIContainer
|
+--UIStateContainer
|
+--UIPanel
|
+--UIScroll
public UIScroll();
Creates a horizontal scroll track control. By default, the control has a range of 0 to 100.
public UIScroll(int style);
Creates a scroll track control with the specified style. By default, the control has a range of 0 to 100.
Parameter | Description |
style
| The style of the control. You can pass any bitwise combination of the following values:
|
Exceptions:
IllegalArgumentException
if an undefined style was specified.
public UIScroll(int style, int min, int max, int page, int line, int pos);
Creates a scroll track control with the specified style and scroll information.
Parameter | Description |
style
| The style of the control. You can pass any bitwise combination of the following values:
|
min
| The minimum scroll position in the control's range.
|
max
| The maximum scroll position in the control's range.
|
page
| The number of scroll positions associated with a page.
|
line
| The number of scroll positions associated with a line.
|
pos
| The current scroll position.
|
Remarks:
If the NONPROPORTIONAL style is not set and the page value is nonzero, the size of the THUMB component represents the ratio of page to range, and the maximum positions the UIScroll object can return are ScrollMaxScrollPage - 1, or ScrollMin (depending on which is larger). Otherwise, the size of the THUMB will be a constant value. For more information about range, page, and line values, see the UIScroll class.
Exceptions:
IllegalArgumentException
if an undefined style was specified.
public boolean action(Event e, Object o);
Responds to events sent from the scroll track control's components.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
e
| The event posted to the scroll track control.
|
o
| The object that posted the event.
|
Remarks:
This method adjusts the control's current position, based on one of the following actions:
- Dragging the THUMB component with the mouse. The current position is moved in increments or decrements of one scroll position.
- Pressing the PAGE_DOWN or PAGE_UP component with the mouse. The current position is moved in increments or decrements, respectively, of one line less than a full page.
- Pressing the LINE_DOWN or LINE_UP component with the mouse, if the control is a UIScrollBar object. The current position is moved in increments or decrements, respectively, of one line.
public IUIComponent add(int index, IUIComponent comp);
Adds the specified component at the given layout index. If a component already exists at this index, it is replaced with the specified component.
Return Value:
Returns the component that was added, if successful; otherwise, returns null.
Parameter | Description |
index
| The layout index of the component to be added. Possible values include THUMB, PAGE_UP, or PAGE_DOWN.
|
comp
| The component to be added.
|
Exceptions:
IllegalArgumentException
if an undefined index was specified.
See Also: getLayoutComponent
public synchronized void addAdjustmentListener(IUIAdjustmentListener l);
Adds the specified adjustment listener. The listener receives all adjustment events generated for the control.
Return Value:
No return value.
Parameter | Description |
l
| The adjustment listener to be added.
|
See Also: removeAdjustmentListener
public IUIComponent getLayoutComponent(int index);
Retrieves the component at the specified layout index.
Return Value:
Returns the specified component, if found; otherwise, returns null.
Parameter | Description |
index
| The layout index of the component to be retrieved. Possible values include THUMB, PAGE_UP, or PAGE_DOWN.
|
Exceptions:
IllegalArgumentException
if an undefined index was specified.
See Also: add
public Dimension getMinimumSize();
Retrieves the minimum size (in pixels) of the scroll track control. The minimum size is based on the preferred size of each component.
Return Value:
Returns a Dimension object containing the control's minimum size.
See Also: getPreferredSize
public Point getPosition();
Retrieves the position of the scroll track control.
Return Value:
Returns a Point object containing the current position.
Remarks:
This method implements getPosition in the IUIPosition interface. If the scroll track is horizontal, the x coordinate of the returned Point is the current scroll position; the y coordinate is zero. If the scroll track is vertical, the x coordinate is zero; the y coordinate is the current scroll position.
See Also: getScrollPos, getXPosition, getYPosition, setPosition
public Dimension getPreferredSize();
Retrieves the preferred size (in pixels) of the scroll track control. The preferred size is based on the preferred size of each component.
Return Value:
Returns a Dimension object containing the control's preferred size.
See Also: getMinimumSize
public int getRoleCode();
Retrieves the ROLE_SYSTEM code that best describes the role of the scroll track control.
Return Value:
Returns the ROLE_SYSTEM_SCROLLBAR code.
public int getScrollLine();
Retrieves the number of scroll positions associated with a line.
Return Value:
Returns the number of scroll positions in a line.
Remarks:
This method implements getScrollLine method in the IUIScroll interface. For more information about line values, see the UIScroll class.
See Also: setScrollLine
public int getScrollMax();
Retrieves the maximum value in the scroll track control's range.
Return Value:
Returns the maximum scroll position.
Remarks:
This method implements getScrollMax in the IUIScroll interface.
See Also: getScrollMin, setScrollMax
public int getScrollMin();
Retrieves the minimum value in the scroll track control's range.
Return Value:
Returns the minimum scroll position.
Remarks:
This method implements getScrollMin in the IUIScroll interface.
See Also: getScrollMax, setScrollMin
public int getScrollPage();
Retrieves the number of scroll positions associated with a page.
Return Value:
Returns the number of scroll positions in a page.
Remarks:
This method implements getScrollPage in the IUIScroll interface. For more information about page values, see the UIScroll overview.
See Also: setScrollPage
public int getScrollPos();
Retrieves the position of the scroll track control.
Return Value:
Returns the current scroll position.
Remarks:
This method implements getScrollPos in the IUIScroll interface.
See Also: getPosition, setScrollPos
public int getStyle();
Retrieves the current style of the scroll track control.
Return Value:
Returns an integer containing the current style settings. For a list of possible styles, see setStyle.
public int getXPosition();
Retrieves the horizontal scroll position of the scroll track control.
Return Value:
Returns the current scroll position if the control is horizontal; otherwise, returns 0.
Remarks:
This method implements getXPosition in the IUIPosition interface.
See Also: getYPosition, getPosition, setXPosition
public int getYPosition();
Retrieves the vertical scroll position of the scroll track control.
Return Value:
Returns the current scroll position if the control is vertical; otherwise, returns 0.
Remarks:
This method implements getYPosition in the IUIPosition interface.
See Also: getXPosition, getPosition, setYPosition
public boolean isKeyable();
Determines whether the scroll track control can receive keyboard input.
Return Value:
Returns true if the control can receive keyboard input; otherwise, returns false.
Remarks:
If the NOKEY style is set, this method returns false.
public boolean isScrollable();
Determines whether the control supports scrolling, based on its range and page values.
Return Value:
Returns true if the control must scroll; otherwise, returns false if scrolling is unnecessary.
Remarks:
This method implements isScrollable in the IUIScroll interface. If the scroll track control has the NOSHOW style or if scrolling is unnecessary, the control will be hidden. If the NOHIDE style is set, the control will be disabled if scrolling is unnecessary.
public void layout();
Lays out the components of the scroll track control.
Return Value:
No return value.
Remarks:
If the scroll track control has the NOSHOW style or if scrolling is unnecessary, the control will be hidden. If the NOHIDE style is set, the control will be disabled if scrolling is unnecessary.
public boolean mouseDrag(Event e, int x, int y);
Responds to the THUMB component being dragged with the mouse.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
e
| The event posted to the control.
|
x
| The x coordinate of the event.
|
y
| The y coordinate of the event.
|
Remarks:
As the THUMB component is dragged, this method adjusts its position accordingly.
protected void processAdjustmentEvent(UIAdjustmentEvent e);
Processes adjustment events.
Return Value:
No return value.
Parameter | Description |
e
| The adjustment event.
|
Remarks:
This method is called by processEvent and dispatches the event to a registered adjustment listener. When overriding this method, call the super method processAdjustmentEvent to ensure the default event processing continues normally.
See Also: addAdjustmentListener
protected void processEvent(UIEvent e);
Processes the specified event.
Return Value:
No return value.
Parameter | Description |
e
| The event.
|
Remarks:
This method is automatically invoked if a listener has been registered through a call to addXXXListener. Depending on the type of event, processEvent calls one of the following methods.
When overriding processEvent, call the super method processEvent to ensure the default event processing continues normally.
public synchronized void removeAdjustmentListener(IUIAdjustmentListener l);
Removes the specified adjustment listener. The listener no longer receives the control's adjustment events.
Return Value:
No return value.
Parameter | Description |
l
| The adjustment listener to be removed.
|
See Also: addAdjustmentListener
public int scrollEnd();
Moves the current scroll position to the maximum range value.
Return Value:
Returns the control's new scroll position.
Remarks:
This method implements scrollEnd in the IUIScroll interface.
See Also: scrollHome
public int scrollHome();
Moves the current scroll position to the minimum range value.
Return Value:
Returns the control's new scroll position.
Remarks:
This method implements scrollHome in the IUIScroll interface.
See Also: scrollEnd
public int scrollLineDown();
Increments the current scroll position by one line.
Return Value:
Returns the control's new scroll position.
Remarks:
This method implements scrollLineDown in the IUIScroll interface. For more information about line values, see the UIScroll overview.
See Also: scrollLineUp
public int scrollLineUp();
Decrements the current scroll position by one line.
Return Value:
Returns the control's new scroll position.
Remarks:
This method implements scrollLineUp in the IUIScroll interface. For more information about line values, see the UIScroll overview.
See Also: scrollLineDown
public int scrollPageDown();
Increments the current scroll position by one line less than a full page.
Return Value:
Returns the control's new scroll position.
Remarks:
This method implements scrollPageDown in the IUIScroll interface. If the difference between the page and line values is negative or zero, the scroll position is incremented by one scroll position. For more information about page and line values, see the UIScroll overview.
See Also: scrollPageUp
public int scrollPageUp();
Decrements the current scroll position by one line less than a full page.
Return Value:
Returns the control's new scroll position.
Remarks:
This method implements scrollPageUp in the IUIScroll interface. If the difference between the page and line values is negative or zero, the scroll position is decremented by one scroll position. For more information about page and line values, see the UIScroll overview.
See Also: scrollPageDown
public void setPosition(Point pt);
Sets the position of the scroll track control, based on the specified Point.
Return Value:
No return value.
Parameter | Description |
pt
| The requested position for the scroll track control. The x and y coordinates of pt specify the horizontal and vertical scroll positions (in pixels), respectively.
|
Remarks:
This method implements setPosition in the IUIPosition interface. If the scroll track is horizontal, the x coordinate of the returned Point is the new scroll position, and the y coordinate is zero. If the scroll track is vertical, the x coordinate is zero and the y coordinate is the new scroll position. Depending on the control's range, these coordinates may differ from those of the parameter pt.
See Also: setScrollPos, setXPosition, setYPosition, getPosition
public void setPosition(int x, int y);
Sets the position of the scroll track control, based on the specified values.
Return Value:
No return value.
Parameter | Description |
x
| The requested horizontal scroll position (in pixels).
|
y
| The requested vertical scroll position (in pixels).
|
Remarks:
This method implements setPosition in the IUIPosition interface. If the scroll track is horizontal, the x coordinate of the returned Point is the new scroll position, and the y coordinate is zero. If the scroll track is vertical, the x coordinate is zero and the y coordinate is the scroll position. Depending on the control's range, these coordinates may differ from the x and y parameters.
See Also: setScrollPos, setXPosition, setYPosition, getPosition
public int setScrollInfo(int min, int max, int page, int line, int pos,
boolean notify);
Sets the specified scroll information and adjusts the control's current position accordingly.
Return Value:
Returns the control's new scroll position after setting the specified values.
Parameter | Description |
min
| The minimum scroll position in the control's range.
|
max
| The maximum scroll position in the control's range.
|
page
| The number of scroll positions associated with a page.
|
line
| The number of scroll positions associated with a line.
|
pos
| The current scroll position.
|
notify
| Set this parameter to true if the object should post events when the scroll information has changed.
|
Remarks:
If the NONPROPORTIONAL style is not set and the page value is nonzero, the size of the THUMB component represents the ratio of page to range, and the maximum positions the UIScroll object can return are ScrollMaxScrollPage - 1, or ScrollMin (depending on which is larger). Otherwise, the size of the THUMB will be a constant value. For more information about range, page, and line values, see the UIScroll overview.
public int setScrollInfo(int min, int max, int page, int line, int pos);
Sets the specified scroll information and adjusts the control's current position accordingly. This method does not post events.
Return Value:
Returns the control's new scroll position after setting the specified values.
Parameter | Description |
min
| The minimum scroll position in the control's range.
|
max
| The maximum scroll position in the control's range.
|
page
| The number of scroll positions associated with a page.
|
line
| The number of scroll positions associated with a line.
|
pos
| The current scroll position.
|
Remarks:
This method implements setScrollInfo in the IUIScroll interface. If the NONPROPORTIONAL style is not set and the page value is nonzero, the size of the THUMB component represents the ratio of page to range. Otherwise, the size of the THUMB represents a scroll position.
For more information about range, page, and line values, see the UIScroll overview.
public void setScrollLine(int line);
Sets the number of scroll positions associated with a line, and adjusts the control's current position accordingly. This method does not post events.
Return Value:
No return value.
Parameter | Description |
line
| The number of scroll positions to be associated with a line.
|
Remarks:
This method implements setScrollLine in the IUIScroll interface. For more information about line values, see the UIScroll class.
See Also: getScrollLine
public int setScrollLine(int line, boolean notify);
Sets the number of scroll positions associated with a line, and adjusts the control's current position accordingly. If notify is true, the object will post appropriate events when the scroll information has changed.
Return Value:
Returns the control's new scroll position after setting the specified value.
Parameter | Description |
line
| The number of scroll positions to be associated with a line.
|
notify
| Set this parameter to true if the object should post events when the scroll information has changed.
|
Remarks:
For more information about line values, see the UIScroll overview.
See Also: getScrollLine
public void setScrollMax(int max);
Sets the maximum range value and adjusts the control's current position accordingly.
Return Value:
No return value.
Parameter | Description |
max
| The maximum scroll position.
|
Remarks:
This method implements setScrollMax in the IUIScroll interface.
See Also: setScrollMin, getScrollMax
public void setScrollMin(int min);
Sets the minimum range value and adjusts the control's current position accordingly.
Return Value:
No return value.
Parameter | Description |
min
| The minimum scroll position.
|
Remarks:
This method implements setScrollMin in the IUIScroll interface.
See Also: setScrollMax, getScrollMin
public void setScrollPage(int page);
Sets the number of scroll positions associated with a page, and adjusts the control's current position accordingly. This method does not post events.
Return Value:
No return value.
Parameter | Description |
page
| The number of scroll positions to be associated with a page.
|
Remarks:
If the NONPROPORTIONAL style is not set and the page value is nonzero, the size of the THUMB component represents the ratio of page to range, and the maximum positions the UIScroll object can return are ScrollMaxScrollPage - 1, or ScrollMin (depending on which is larger). Otherwise, the size of the THUMB will be a constant value. For more information about range, page, and line values, see the UIScroll overview.
See Also: getScrollPage
public int setScrollPage(int page, boolean notify);
Sets the number of scroll positions associated with a page, and adjusts the control's current position accordingly. If notify is true, the object will post appropriate events when the scroll information has changed.
Return Value:
Returns the control's new scroll position after setting the specified value.
Parameter | Description |
page
| The number of scroll positions to be associated with a page.
|
notify
| Set this parameter to true if the object should post events when the scroll information has changed.
|
Remarks:
If the NONPROPORTIONAL style is not set and the page value is nonzero, the size of the THUMB component represents the ratio of page to range. Otherwise, the size of the THUMB represents a scroll position. For more information about page values, see the UIScroll overview.
See Also: getScrollPage
public void setScrollPos(int pos);
Sets the control's current position to the specified scroll position. This method does not post events.
Return Value:
No return value.
Parameter | Description |
pos
| The position for the scroll track control.
|
Remarks:
This method implements setScrollPos in the IUIScroll interface. Depending on the control's range, the returned position may differ from the pos parameter.
See Also: setPosition, getScrollPos
public int setScrollPos(int pos, boolean notify);
Sets the control's current position to the specified scroll position. If notify is true, the object will post appropriate events when the scroll information has changed.
Return Value:
Returns the control's new scroll position after setting the specified value.
Parameter | Description |
pos
| The position for the scroll track control.
|
notify
| Set this parameter to true if the object should post events when the scroll information has changed.
|
Remarks:
Depending on the control's range, the returned position may differ from the pos parameter.
See Also: setPosition, getScrollPos
public int setScrollRange(int min, int max);
Sets the scroll track control's range, and adjusts the control's current position accordingly.
Return Value:
Returns the control's new scroll position after setting the specified values.
Parameter | Description |
min
| The minimum scroll position.
|
max
| The maximum scroll position.
|
Remarks:
This method implements setScrollRange in the IUIScroll interface.
public void setStyle(int style);
Sets the current style for the scroll track control.
Return Value:
No return value.
Parameter | Description |
style
| The style of the control. You can pass any bitwise combination of the following values:
|
Exceptions:
IllegalArgumentException
if an undefined style was specified.
See Also: getStyle
public void setXPosition(int x);
Sets the horizontal scroll position of the control.
Return Value:
No return value.
Parameter | Description |
x
| The requested horizontal scroll position.
|
Remarks:
This method implements setXPosition in the IUIPosition interface. If the scroll track is horizontal, the returned position may differ from the x parameter, depending on the control's range.
See Also: setYPosition, setPosition, getXPosition
public void setYPosition(int y);
Sets the vertical scroll position of the control.
Return Value:
No return value.
Parameter | Description |
y
| The requested vertical scroll position.
|
Remarks:
This method implements setYPosition in the IUIPosition interface. If the scroll track is vertical, the returned position may differ from the y parameter, depending on the control's range.
See Also: setXPosition, setPosition, getYPosition
- NOHIDE
- Specifies that an unneeded scroll track will be disabled rather than hidden.
- NOKEY
- Specifies that the scroll track control cannot receive keyboard input.
- NONPROPORTIONAL
- Specifies that the size of the thumb component is constant, rather than the ratio of page to range. This style is used with a UISlider object.
- NOSHOW
- Specifies that the scroll track control will always be hidden.
- PAGE_DOWN
- The layout index for the track area below or to the right of the thumb.
- PAGE_UP
- The layout index for the track area above or to the left of the thumb.
- THICK
- Specifies that the thumb has a thick edge.
- THUMB
- The layout index for the thumb component, which indicates the current position of the scroll track control.
- VERTICAL
- Specifies that the scroll track control will be vertical.