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 |
An NSTextField is a kind of NSControl that displays text that the user can select or edit and that sends its action message to its target when the user presses the Return key while editing.
NSTextField uses NSTextFieldCell to implement its user interface.
Creates an NSTextField with a zero-sized frame rectangle.
public NSTextField
()
Creates an NSTextField with frameRect as its frame rectangle.
public NSTextField
(NSRect frameRect)
Returns true
if the receiver is editable, false
otherwise.
public boolean acceptsFirstResponder
()
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.
public boolean allowsEditingTextAttributes
()
You can change text attributes programmatically regardless of this setting.
Returns the color of the background that the receiver draws behind the text.
public NSColor backgroundColor
()
Returns the receiver’s bezel style.
public int bezelStyle
()
Possible return values are described in NSTextFieldCell’s “Constants.”
Returns the receiver’s delegate.
public Object delegate
()
textShouldBeginEditing
textShouldEndEditing
textDidBeginEditing
textDidEndEditing
textDidChange
setDelegate
Returns true
if the receiver’s cell draws its background color behind its text, false
if it draws no background.
public boolean drawsBackground
()
backgroundColor
drawsBackground
(NSTextFieldCell)setDrawsBackground
Returns true
if the receiver allows the user to drag image files into it, false
if it doesn’t accept dragged images.
public boolean importsGraphics
()
You can add images programmatically regardless of this setting.
allowsEditingTextAttributes
importsGraphics
(NSTextView)setImportsGraphics
Returns true
if the receiver draws a bezeled frame around its contents, false
if it doesn’t.
public boolean isBezeled
()
Returns true
if the receiver draws a solid black border around its contents, false
if it doesn’t.
public boolean isBordered
()
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).
public boolean isEditable
()
Returns true
if the user is allowed to select the receiver’s text, false
if the user isn’t allowed to select it.
public boolean isSelectable
()
Selectable text isn’t necessarily editable; use isEditable
to check for editability.
This action method ends editing and selects the entire contents of the receiver if it’s selectable.
public void selectText
(Object sender)
However, if the receiver isn’t in some window’s view hierarchy, this method has no effect.
Controls whether the receiver allows the user to change font attributes of the receiver’s text.
public void setAllowsEditingTextAttributes
(boolean flag)
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.
Sets the color of the background that the receiver draws behind the text to aColor.
public void setBackgroundColor
(NSColor aColor)
Controls whether the receiver draws a bezeled border around its contents.
public void setBezeled
(boolean flag)
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
.
Sets the receiver’s bezel style to be style.
public void setBezelStyle
(int style)
Possible values for style are described in NSTextFieldCell’s “Constants.” You must have already sent the receiver setBezeled
with an argument of true
.
Controls whether the receiver draws a solid black border around its contents.
public void setBordered
(boolean flag)
If flag is true
, then it draws a border; if flag is false
, it draws no border.
Sets the receiver’s delegate to anObject.
public void setDelegate
(Object anObject)
textShouldBeginEditing
textShouldEndEditing
textDidBeginEditing
textDidEndEditing
textDidChange
delegate
Controls whether the receiver draws its background color behind its text.
public void setDrawsBackground
(boolean flag)
If flag is true
, then it does; if flag is false
, then it draws nothing behind its text.
setBackgroundColor
setDrawsBackground
(NSTextFieldCell)drawsBackground
Controls whether the user can edit the receiver’s text.
public void setEditable
(boolean flag)
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.
Controls whether the receiver allows the user to drag image files into it.
public void setImportsGraphics
(boolean flag)
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.
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.
Sets the color used to draw the receiver’s text to aColor.
public void setTextColor
(NSColor aColor)
setBackgroundColor
setTextColor
(NSTextFieldCell)textColor
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.
public void setTitleWithMnemonic
(String aString)
Mnemonics are not supported in Mac OS X.
Returns the color used to draw the receiver’s text.
public NSColor textColor
()
backgroundColor
textColor
(NSTextFieldCell)setTextColor
Posts a ControlTextDidBeginEditingNotification
to the default notification center.
public void textDidBeginEditing
(NSNotification aNotification)
This action causes the receiver’s delegate to receive a controlTextDidBeginEditing
message. See the NSControl class specification for more information on the text delegate method.
Forwards this message to the receiver’s cell if it responds and posts a ControlTextDidChangeNotification
to the default notification center.
public void textDidChange
(NSNotification aNotification)
This method causes the receiver’s delegate to receive a controlTextDidChange
message. See the NSControl class specification for more information on the text delegate method.
Handles an end of editing NSNotification aNotification.
public void textDidEndEditing
(NSNotification aNotification)
After validating the new value, posts a ControlTextDidEndEditingNotification
to the default notification center. This posting causes the receiver’s delegate to receive a controlTextDidEndEditing
message. After this message, sends endEditing
to the receiver’ cell and handles the key that caused editing to end:
If the user ended editing by pressing Return, this method tries to send the receiver’s action to its target; if unsuccessful, it sends performKeyEquivalent
to its NSView (for example, to handle the default button on a panel); if that also fails, the receiver simply selects its text.
If the user ended editing by pressing Tab or Shift-Tab, the receiver tries to have its NSWindow select its next or previous key view, using the NSWindow method selectKeyViewFollowingView
or selectKeyViewPrecedingView
. If unsuccessful in doing this, the receiver simply selects its text.
See the NSControl class specification for more information on the text delegate method.
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. The textObject argument is the NSText object that invoked this method. See the NSControl class specification for more information on the text delegate method.
Performs validation on the receiver’s new value using NSCell’s isEntryAcceptable
, sending the receiver’s error action to its target if validation fails.
public boolean textShouldEndEditing
(NSText textObject)
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
. The textObject argument is the NSText object that invoked this method. See the NSControl class specification for more information on the text delegate method.
© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)