Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Implements | |
Package | com.apple.cocoa.application |
Companion guide | Drawing and Views |
An NSScroller object is a user control for scrolling a document view within a container view. You normally don’t need to program with NSScrollers, as Interface Builder allows you to fully configure them with an NSScrollView.
Scrolling by small and large increments
Proportional knob showing visible amount of document
hitPart
Indicates where the user clicked the NSScroller.
floatValue
(NSControl)Returns the position of the NSScroller’s knob.
setFloatValueAndKnobProportion
Sets the position and size of the NSScroller’s knob.
An NSScroller controls scrolling of a document view within an NSScrollView’s clip view (or potentially another kind of container view). It typically displays a pair of buttons that the user can click to scroll by a small amount (called a line increment or decrement) and Alt-click to scroll by a large amount (called a page increment or decrement), plus a slot containing a knob that the user can drag directly to the desired location. The knob indicates both the position within the document view and, by varying in size within the slot, the amount visible relative to the size of the document view. You can configure whether an NSScroller uses scroll buttons, but it always draws the knob when there’s room for it.
Don’t use an NSScroller when an NSSlider would be better. A slider represents a range of values for something in the application and lets the user choose a setting. A scroller represents the relative position of the visible portion of a view and lets the user choose which portion to view.
Creates an NSScroller with a zero-size frame rectangle.
public NSScroller
()
Creates an NSScroller with frameRect as its frame rectangle.
public NSScroller
(NSRect frameRect)
Returns the width of “normal-sized” instances.
public static float scrollerWidth
()
NSScrollView uses this value to lay out its components. Subclasses that use a different width should override this method.
Returns the width of the scroller based on controlSize.
public static float scrollerWidthForControlSize
(int controlSize)
Valid values for controlSize are described in NSCell’s “Constants.”
Returns the location of the scroll buttons within the receiver, as described under “Constants.”
public int arrowsPosition
()
Checks to see if there is enough room in the receiver to display the knob and buttons.
public void checkSpaceForParts
()
usableParts
returns the state calculated by this method. You should never need to invoke this method; it’s invoked automatically whenever the NSScroller’s size changes.
Returns the size of the receiver.
public int controlSize
()
Valid return values are described in “Constants.”
Returns the receiver’s control tint.
public int controlTint
()
Valid return values are described in “Constants.”
Draws the scroll button indicated by arrow, which is either IncrementArrow
(the down or right scroll button) or DecrementArrow
(up or left).
public void drawArrow
(int arrow, boolean flag)
If flag is true
, the button is drawn highlighted; otherwise it’s drawn normally. You should never need to invoke this method directly, but may wish to override it to customize the appearance of scroll buttons.
Draws the knob
public void drawKnob
()
. You should never need to invoke this method directly, but may wish to override it to customize the appearance of the knob.
Caches images for the scroll buttons and knob.
public void drawParts
()
It’s invoked only once when the NSScroller is created. You may want to override this method if you alter the look of the NSScroller, but you should never invoke it directly.
Highlights or unhighlights the scroll button the user clicked.
public void highlight
(boolean flag)
The receiver invokes this method while tracking the mouse; you should not invoke it directly. If flag is true
, the appropriate part is drawn highlighted; otherwise it’s drawn normally.
Returns a part code indicating the manner in which the scrolling should be performed.
public int hitPart
()
See “Constants” for a list of part codes.
This method is typically invoked by an NSScrollView to determine how to scroll its document view when it receives an action message from the NSScroller.
Returns the portion of the knob slot the knob should fill, as a floating-point value from 0.0 (minimal size) to 1.0 (fills the slot).
public float knobProportion
()
Returns the rectangle occupied by aPart, which for this method is interpreted literally rather than as an indicator of scrolling direction.
public NSRect rectForPart
(int aPart)
See “Constants” for a list of possible values for aPart.
Note the interpretations of DecrementPage
and IncrementPage
. The actual part of an NSScroller that causes page-by-page scrolling varies, so as a convenience these part codes refer to useful parts different from the scroll buttons.
Returns NSRect.ZeroRect
if the part requested isn’t present on the receiver.
Sets the location of the scroll buttons within the receiver to location, or inhibits their display.
public void setArrowsPosition
(int location)
See “Constants” for a list of possible values for location.
Sets the size of the receiver.
public void setControlSize
(int controlSize)
Valid values for controlSize are described in “Constants.”
Sets the receiver’s control tint.
public void setControlTint
(int controlTint)
Valid values for controlTint are described in “Constants.”
Sets the position of the knob to aFloat, which is a value from 0.0 (indicating the top or left end) to 1.0 (the bottom or right end).
public void setFloatValueAndKnobProportion
(float aFloat, float knobProp)
Also sets the proportion of the knob slot filled by the knob to knobProp, also a value from 0.0 (minimal size) to 1.0 (fills the slot).
floatValue
(NSControl)knobProportion
Returns the part that would be hit by a mouse-down event at aPoint (expressed in the window’s coordinate system).
public int testPart
(NSPoint aPoint)
See “Constants” for a list of possible return values.
Note the interpretations of DecrementPage
and IncrementPage
. The actual part of an NSScroller that causes page-by-page scrolling varies, so as a convenience these part codes refer to useful parts different from the scroll buttons.
Tracks the knob and sends action messages to the receiver’s target.
public void trackKnob
(NSEvent theEvent)
This method is invoked automatically when the receiver receives theEvent mouse-down event in the knob; you should not invoke it directly.
Tracks the scroll buttons and sends action messages to the receiver’s target.
public void trackScrollButtons
(NSEvent theEvent)
This method is invoked automatically when the receiver receives theEvent mouse-down event in a scroll button; you should not invoke this method directly.
Returns a value indicating which parts of the receiver are displayed and usable.
public int usableParts
()
See “Constants” for a list of possible values.
These constants specify the different parts of the scroller:
Constant | Description |
---|---|
Knob | Directly to the NSScroller’s value, as given by |
KnobSlot | Directly to the NSScroller’s value, as given by |
DecrementLine | Up or left by a small amount. |
DecrementPage | Up or left by a large amount. |
IncrementLine | Down or right by a small amount. |
IncrementPage | Down or right by a large amount. |
NoPart | Don’t scroll at all. |
These constants describe the two scroller buttons and are used by drawArrow
:
Constant | Description |
---|---|
IncrementArrow | The down or right scroll button. |
DecrementArrow | The up or left scroll button. |
These constants specify where the scroller’s buttons appear and are used by arrowsPosition
and setArrowsPosition
:
These constants specify which parts of the scroller are visible:
These constants specify control tints:
Constant | Description |
---|---|
DefaultControlTint | The current default tint setting. |
ClearControlTint | Clear control tint. |
BlueControlTint | Aqua control tint |
GraphiteControlTint | Graphite control tint |
These constants specify control size:
© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)