Developer Documentation
PATH  Mac OS X Documentation > Application Kit Reference: Java

Table of Contents

NSTextField


Inherits from:
NSControl : NSView : NSResponder : NSObject
Package:
com.apple.yellow.application


Class Description


An NSTextField is a kind of NSControl that displays text that the user can select or edit, and which sends its action message to its target when the user presses the Return key while editing. Like other controls, it also performs validation on its value when edited; if the value isn't valid it sends a special error action message to its target. An NSTextField can be assigned a delegate, who is then informed of delegate messages sent by the window's field editor, such as textShouldEndEditing. See the NSWindow and NSTextView class specifications for more information on a window's field editor.

Typical of several kinds of control, NSTextField allows you to set its text and background color, whether it draws the background, and whether it draws a bezel or border around its text. Note that the text and background colors of selected text are configurable. The selected text color overshadows any actual text color applied to the text while it's selected (this is generally the case with controls).

You can link text fields together in their window's key view loop, as described in the NSWindow class specification.




Method Types


Constructors
NSTextField
Controlling editability and selectability
setEditable
isEditable
setSelectable
isSelectable
Setting the error action
setErrorAction
errorAction
Controlling rich text behavior
setAllowsEditingTextAttributes
allowsEditingTextAttributes
setImportsGraphics
importsGraphics
Setting the text color
setTextColor
textColor
Controlling the background
setBackgroundColor
backgroundColor
setDrawsBackground
drawsBackground
Setting a border
setBezeled
isBezeled
setBordered
isBordered
Linking text fields together
setNextText
nextText
setPreviousText
previousText
Selecting the text
selectText
Working with the responder chain
acceptsFirstResponder
Using keyboard interface control
setTitleWithMnemonic
Setting the delegate
setDelegate
delegate
Text delegate methods
textShouldBeginEditing
textDidBeginEditing
textDidChange
textShouldEndEditing
textDidEndEditing


Constructors



NSTextField

public NSTextField()

Description forthcoming.

public NSTextField(NSRect frameRect)

Description forthcoming.


Instance Methods



acceptsFirstResponder

public boolean acceptsFirstResponder()

Returns true if the receiver is editable or selectable, false otherwise.

allowsEditingTextAttributes

public boolean allowsEditingTextAttributes()

Returns true if the receiver allows the user to change font attributes of the receiver's text, false if the user isn't permitted to do so. You can change text attributes programmatically regardless of this setting.

See Also: importsGraphics, setAllowsEditingTextAttributes



backgroundColor

public NSColor backgroundColor()

Returns the color of the background that the receiver draws behind the text.

See Also: drawsBackground, setBackgroundColor



delegate

public Object delegate()

Returns the receiver's delegate.

See Also: textShouldBeginEditing, textShouldEndEditing, textDidBeginEditing, textDidEndEditing, textDidChange, setDelegate



drawsBackground

public boolean drawsBackground()

Returns true if the receiver's cell draws its background color behind its text, false if it draws no background.

See Also: backgroundColor, drawsBackground (NSTextFieldCell), setDrawsBackground



errorAction

public NSSelector errorAction()

Returns the selector for the message sent to the receiver's target whenever a validation error occurs.

See Also: textShouldEndEditing, setErrorAction



importsGraphics

public boolean importsGraphics()

Returns true if the receiver allows the user to drag image files into it, false if it doesn't accept dragged images. You can add images programmatically regardless of this setting.

See Also: allowsEditingTextAttributes, importsGraphics (NSTextView), setImportsGraphics



isBezeled

public boolean isBezeled()

Returns true if the receiver draws a bezeled frame around its contents, false if it doesn't.

See Also: isBordered, setBezeled



isBordered

public boolean isBordered()

Returns true if the receiver draws a solid black border around its contents, false if it doesn't.

See Also: isBezeled, setBordered



isEditable

public boolean isEditable()

Returns true if the user is allowed to select and edit the receiver's text, false if the user isn't allowed to edit it (though the user may be able to select it).

See Also: isSelectable, setEditable



isSelectable

public boolean isSelectable()

Returns true if the user is allowed to select the receiver's text, false if the user isn't allowed to select it. Selectable text isn't necessarily editable; use isEditable to check for editability.

See Also: setSelectable



nextText

public Object nextText()

Returns the receiver's next key view, the object that's made first responder when the user presses the Tab key while editing the receiver. See the description of the nextKeyView method in NSView for more information.

See Also: previousText, setNextText



previousText

public Object previousText()

Returns the receiver's previous key view, the object that's made first responder when the user presses Shift-Tab while editing the receiver. See the description of the previousKeyView method in NSView for more information.

See Also: nextText, setPreviousText



selectText

public void selectText(Object sender)

Selects the entire contents of the receiver if it's selectable. However, if the receiver isn't in some window's view hierarchy, this method has no effect.

See Also: isSelectable



setAllowsEditingTextAttributes

public void setAllowsEditingTextAttributes(boolean flag)

Controls whether the receiver allows the user to change font attributes of the receiver's text. If flag is true, the user is permitted to make such changes; if flag is false, the user isn't so permitted. You can change text attributes programmatically regardless of this setting.

See Also: setImportsGraphics, allowsEditingTextAttributes



setBackgroundColor

public void setBackgroundColor(NSColor aColor)

Sets the color of the background that the receiver draws behind the text to aColor.

See Also: setDrawsBackground, backgroundColor



setBezeled

public void setBezeled(boolean flag)

Controls whether the receiver draws a bezeled border around its contents. If flag is false, it draws no border; if flag is true, it draws a bezeled border and invokes setDrawsBackground with an argument of false.

See Also: isBezeled, setBordered



setBordered

public void setBordered(boolean flag)

Controls whether the receiver draws a solid black border around its contents. If flag is true, then it draws a border; if flag is false, it draws no border.

See Also: isBordered, setBezeled



setDelegate

public void setDelegate(Object anObject)

Sets the receiver's delegate to anObject.

See Also: textShouldBeginEditing, textShouldEndEditing, textDidBeginEditing, textDidEndEditing, textDidChange, delegate



setDrawsBackground

public void setDrawsBackground(boolean flag)

Controls whether the receiver draws its background color behind its text. If flag is true, then it does; if flag is false, then it draws nothing behind its text.

See Also: setBackgroundColor, setDrawsBackground (NSTextFieldCell), drawsBackground



setEditable

public void setEditable(boolean flag)

Controls whether the user can edits the receiver's text. If flag is true, then the user is allowed to both select and edit text. If flag is false, then the user isn't permitted to edit text, and the receiver's selectability is restored to its previous value. For example, if an NSTextField is selectable but not editable, then made editable for a time, then made not editable, it remains selectable. To guarantee that text is neither editable nor selectable, simply use setSelectable to turn off selectability.

See Also: isEditable



setErrorAction

public void setErrorAction(NSSelector aSelector)

Sets the selector for the message sent to the receiver's target whenever a validation error occurs to aSelector.

See Also: textShouldEndEditing, errorAction



setImportsGraphics

public void setImportsGraphics(boolean flag)

Controls whether the receiver allows the user to drag image files into it. If flag is true, the receiver accepts dragged images; if flag is false, it doesn't. You can add images programmatically regardless of this setting.

See Also: setAllowsEditingTextAttributes, setImportsGraphics (NSTextView), importsGraphics



setNextText

public void setNextText(Object anObject)

- (void)setNextText:(id)anObject

Sets the receiver's next key view to anObject, which should be a kind of NSView. See the description of the setNextKeyView method in the NSView class specification for more information.

See Also: setPreviousText, nextText



setPreviousText

public void setPreviousText(Object anObject)

Sets the receiver's previous key view to anObject, which should be a kind of NSView. See the description of the setPreviousKeyView: method in the NSView class specification for more information.

See Also: setNextText, previousText



setSelectable

public void setSelectable(boolean flag)

If flag is true, the receiver is made selectable but not editable (use setEditable to make text both selectable and editable). If false, then the text is made neither editable nor selectable.

See Also: setEditable



setTextColor

public void setTextColor(NSColor aColor)

Sets the color used to draw the receiver's text to aColor.

See Also: setBackgroundColor, setTextColor (NSTextFieldCell), textColor



setTitleWithMnemonic

public void setTitleWithMnemonic(String aString)

Sets the receiver's string value to aString, using the first character preceded by an ampersand ('&') as the mnemonic and stripping out that first ampersand character. Use this method only with a non-editable text field being used as a label for another interface component, which you should establish using setNextKeyView. When set up in this fashion, the text field's mnemonic serves to select the other interface component.

textColor

public NSColor textColor()

Returns the color used to draw the receiver's text.

See Also: backgroundColor, textColor (NSTextFieldCell), setTextColor



textDidBeginEditing

public void textDidBeginEditing(NSNotification aNotification)

Posts a ControlTextDidBeginEditingNotification to the default notification center. This causes the receiver's delegate to receive a controlTextDidBeginEditing message. See the NSControl class specification for more information on the text delegate method.

See Also: textDidBeginEditing, textDidChange, textShouldEndEditing, textDidEndEditing



textDidChange

public void textDidChange(NSNotification aNotification)

Forwards this message to the receiver's cell if it responds, and posts a ControlTextDidChangeNotification to the default notification center. This causes the receiver's delegate to receive a controlTextDidChange message. See the NSControl class specification for more information on the text delegate method.

See Also: textShouldBeginEditing, textDidBeginEditing, textShouldEndEditing, textDidEndEditing



textDidEndEditing

public void textDidEndEditing(NSNotification aNotification)

Handles an end to editing. After validating the new value, posts a ControlTextDidEndEditingNotification to the default notification center. This causes the receiver's delegate to receive a controlTextDidEndEditing message. After this, sends endEditing to the receiver' cell, and handles the key that caused editing to end:

See the NSControl class specification for more information on the text delegate method.

See Also: textShouldBeginEditing, textDidBeginEditing, textDidChange, textShouldEndEditing



textShouldBeginEditing

public boolean textShouldBeginEditing(NSText textObject)

If the receiver isn't editable, returns false immediately. If it is editable and its delegate responds to controlTextShouldBeginEditing, invokes that method and returns the result. Otherwise simply returns true to allow editing to occur. See the NSControl class specification for more information on the text delegate method.

See Also: textDidBeginEditing, textDidChange, textShouldEndEditing, textDidEndEditing



textShouldEndEditing

public boolean textShouldEndEditing(NSText textObject)

Performs validation on the receiver's new value using NSCell's isEntryAcceptable:, sending the receiver's error action to its target if validation fails. If the new value is valid and the delegate responds to controlTextShouldEndEditing, invokes that method and returns the result, in addition beeping if the delegate returns false. See the NSControl class specification for more information on the text delegate method.

See Also: textShouldBeginEditing, textDidBeginEditing, textDidChange, textDidEndEditing, errorAction




Table of Contents