- Inherits from:
- NSControl : NSView : NSResponder : NSObject
- Package:
- com.apple.yellow.application
An NSSlider displays a range of values for something in the application. An indicator, or knob, notes the current setting. The user can move the knob in the slider's bar to change the setting. If the slider is vertical, its minimum is at its bottom; if it is horizontal, its minimum is at its left.
The minimum and maximum can be obtained with the minValue and maxValue methods, and set with the setMinValue and setMaxValue methods. To read the value represented by the current position of the knob, you use an NSControl method like floatValue; conversely, to send a value to the slider, you use a NSControl method like setFloatValue.
By default, an NSSlider is a continuous NSControl: while the
user drags the slider's knob, the slider sends its action message
continuously. If, instead, you want the slider to reserve its action
message until the mouse is released, invoke setContinuous (an NSControl method)
with an argument of false
.
In its bar, an NSSlider can display an image, a title, or both. The title can be drawn in any color and any font. However, because a title in the bar may be obscured by the slider knob, you will more often label a slider by placing an NSTextField near it.
An NSSlider can have tick marks to either side of it. The values represented by the tick marks are determined by the number of tick marks and the minimum and maximum values of the slider; a slider's values can be pegged to the values represented by the tick marks.
Like most NSControls, NSSlider relies heavily on a related cell class, NSSliderCell. For more information, see the NSSliderCell class specification.
Don't use an NSSlider when an NSScroller would be better. A scroller represents the relative position of the visible portion of a view and lets the user choose which portion to view. A slider represents a range of values for something in the application and lets the user choose a setting.
- Constructors
- NSSlider
- Asking about the slider's appearance
- altIncrementValue
- image
- knobThickness
- isVertical
- Changing the slider's appearance
- setAltIncrementValue
- setImage
- setKnobThickness
- Asking about the slider's title
- title
- titleCell
- titleColor
- titleFont
- Changing the slider's title
- setTitle
- setTitleCell
- setTitleColor
- setTitleFont
- Asking about the value limits
- maxValue
- minValue
- Changing the value limits
- setMaxValue
- setMinValue
- Handling mouse-down events
- acceptsFirstMouse
- Managing tick marks
- allowsTickMarkValuesOnly
- closestTickMarkValueToValue
- indexOfTickMarkAtPoint
- numberOfTickMarks
- rectOfTickMarkAtIndex
- setAllowsTickMarkValuesOnly
- setNumberOfTickMarks
- setTickMarkPosition
- tickMarkPosition
- tickMarkValueAtIndex
public NSSlider()
public NSSlider(NSRect frameRect)
public boolean acceptsFirstMouse(NSEvent mouseDownEvent)
true
by
default, so a single mouse-down event can simultaneously activate
the window and take hold of the slider's knob. If you want the slider to wait for its own mouse-down event, you must override this method.
public boolean allowsTickMarkValuesOnly()
See Also: setAllowsTickMarkValuesOnly
public double altIncrementValue()
Unless you call setAltIncrementValue, altIncrementValue returns -1.0, and the slider behaves no differently with the Alt key down than with it up.
See Also: setAltIncrementValue
public double closestTickMarkValueToValue(double aValue)
See Also: indexOfTickMarkAtPoint
public NSImage image()
null
if no
image has been set.See Also: setImage
public int indexOfTickMarkAtPoint(NSPoint point)
NSArray.NotFound
.
In its implementation of this method, the receiving NSSlider simply
invokes the method of the same name of its NSSliderCell. This method
invokes rectOfTickMarkAtIndex for
each tick mark on the slider until it finds a tick mark containing
the point. See Also: closestTickMarkValueToValue
public int isVertical()
public float knobThickness()
See Also: setKnobThickness
public double maxValue()
See Also: setMaxValue
public double minValue()
See Also: setMinValue
public int numberOfTickMarks()
See Also: setNumberOfTickMarks
public NSRect rectOfTickMarkAtIndex(int index)
See Also: indexOfTickMarkAtPoint
public void setAllowsTickMarkValuesOnly(boolean flag)
See Also: allowsTickMarkValuesOnly
public void setAltIncrementValue(double increment)
If you don't call this method, the slider behaves the same with the Alt key down as with it up. This is also the result when you call setAltIncrementValue with an increment of -1.
public void setImage(NSImage barImage)
The knob may cover part of the image. If you want the image to be visible all the time, you're better off placing it near the slider.
See Also: setImage
public void setKnobThickness(float thickness)
See Also: knobThickness
public void setMaxValue(double maxValue)
See Also: maxValue
public void setMinValue(double minValue)
See Also: minValue
public void setNumberOfTickMarks(int numberOfTickMarks)
See Also: numberOfTickMarks
public void setTickMarkPosition(int position)
NSSliderCell.TickMarksBelow
(the
default) or NSSliderCell.TickMarksAbove
;
for vertical sliders, position can
be NSSliderCell.TickMarksLeft
(the
default) or NSSliderCell.TickMarksRight
.
This method has no effect if no tick marks have been assigned (that
is, numberOfTickMarks returns
zero). In its implementation of this method, the receiving NSSlider
simply invokes the method of the same name of its NSSliderCell.See Also: tickMarkPosition
public void setTitle(String barTitle)
The knob may cover part or all of the title. If you want the title to be visible all the time, you're better off placing a label near the slider.
See Also: title
public void setTitleCell(NSCell titleCell)
See Also: titleCell
public void setTitleColor(NSColor color)
See Also: titleColor
public void setTitleFont(NSFont font)
See Also: titleFont
public int tickMarkPosition()
NSSliderCell.TickMarkBelow
, NSSliderCell.TickMarkAbove
, NSSliderCell.TickMarkLeft
,
or NSSliderCell.TickMarkRight
(the
last two are for vertical sliders). The default alignments are NSSliderCell.TickMarkBelow
and NSSliderCell.TickMarkLeft
.
In its implementation of this method, the receiving NSSlider simply
invokes the method of the same name of its NSSliderCell.See Also: setTickMarkPosition
public double tickMarkValueAtIndex(int index)
public String title()
See Also: setTitle
public NSCell titleCell()
See Also: setTitleCell
public NSColor titleColor()
See Also: setTitleColor
public NSFont titleFont()
See Also: setTitleFont