Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSFontPanel

Inherits from
Implements
Package
com.apple.cocoa.application
Companion guide

Overview

The NSFontPanel class implements the Font panel—a user interface object that displays a list of available fonts, letting the user preview them and change the font used to display text. The actual changes are made through conversion messages sent to the shared NSFontManager instance. There’s only one Font panel for each application.

Tasks

Constructors

Getting the Font Panel

Enabling Font Changes

Updating the Font Panel

Converting Fonts

Working in Modal Loops

Setting an Accessory View

Constructors

NSFontPanel

Creates an empty NSFontPanel.

public NSFontPanel()

Creates a new NSFontPanel.

public NSFontPanel(NSRect contentRect, int styleMask, int backingType, boolean defer)

Discussion

The contentRect argument specifies the location and size of the panel’s content area in screen coordinates. Note that the window server limits window position coordinates to ±16,000 and sizes to 10,000.

The styleMask argument specifies the panel’s style. Either it can be NSWindow.BorderlessWindowMask, or it can contain any of the options described in NSWindow’s “Constants,” combined using the C bitwise OR operator.

Borderless windows display none of the usual peripheral elements and are generally useful only for display or caching purposes; you should normally not need to create them. Also, note that an NSWindow’s style mask should include NSWindow.TitledWindowMask if it includes any of the others.

The backingType argument specifies how the drawing done in the panel is buffered by the object’s window device, and possible values are described in NSWindow’s “Constants.”

The defer argument determines whether the window server creates a window device for the new panel immediately. If defer is true, it defers creating the window until the panel is moved onscreen. All display messages sent are postponed until the panel is created, just before it’s moved onscreen. Deferring the creation of the window improves launch time and minimizes the virtual memory load on the window server.

The new panel creates an instance of NSView to be its default content view. You can replace it with your own object by using the setContentView method.

Creates a new NSFontPanel.

public NSFontPanel(NSRect contentRect, int styleMask, int backingType, boolean defer, NSScreen aScreen)

Discussion

This constructor is equivalent to the preceding one, except contentRect is specified relative to the lower-left corner of aScreen.

If aScreen is null, contentRect is interpreted relative to the lower-left corner of the main screen. The main screen is the one that contains the current key window, or, if there is no key window, the one that contains the main menu. If there’s neither a key window nor a main menu (if there’s no active application), the main screen is the one where the origin of the screen coordinate system is located.

Static Methods

sharedFontPanel

Returns the single NSFontPanel instance for the application, creating it if necessary.

public static NSFontPanel sharedFontPanel()

See Also

sharedFontPanelExists

Returns true if the shared Font panel has been created, false if it hasn’t.

public static boolean sharedFontPanelExists()

See Also

Instance Methods

accessoryView

Returns the receiver’s accessory view.

public NSView accessoryView()

See Also

isEnabled

Returns true if the receiver’s Set button is enabled, false if it isn’t.

public boolean isEnabled()

Discussion

The receiver continues to reflect the font of the selection for cooperating text objects regardless of this setting.

See Also

panelConvertFont

Converts aFont using the settings in the receiver, with the aid of the shared NSFontManager if necessary, and returns the converted font.

public NSFont panelConvertFont(NSFont aFont)

Discussion

If aFont can’t be converted it’s returned unchanged.

For example, if aFont is Helvetica Oblique 12.0 point and the user has selected the Times font family (and nothing else) in the Font panel, the font returned is Times Italic 12.0 point.

See Also

setAccessoryView

Establishes aView as the receiver’s accessory view, allowing you to add custom controls to your application’s Font panel without having to create a subclass.

public void setAccessoryView(NSView aView)

See Also

setEnabled

Controls whether the receiver’s Set button is enabled.

public void setEnabled(boolean flag)

Discussion

If flag is true the Set button is enabled; if flag is false it’s disabled. The receiver continues to reflect the font of the selection for cooperating text objects regardless of this setting.

See Also

setPanelFont

Sets the selected font in the receiver to aFont if flag is false; otherwise selects no font and displays a message in the preview area indicating that multiple fonts are selected.

public void setPanelFont(NSFont aFont, boolean flag)

Discussion

You normally don’t use this method directly; instead, you send setSelectedFont to the shared NSFontManager, which in turn invokes this method.

worksWhenModal

Returns true, regardless of the setting established using the NSPanel method setWorksWhenModal.

public boolean worksWhenModal()

Discussion

This method allows fonts to be changed in modal windows and panels.

See Also

Constants

The constants in the following table specify the available font panel mode masks. They are available only on Mac OS X v10.3 and later.

Constant

Description

FaceModeMask

Display the typeface column.

SizeModeMask

Display the font size column.

CollectionModeMask

Display the font collections column.

StandardModesMask

Display the standard default font panel—that is, including the collections, typeface, and size columns.

AllModesMask

Display all the available adornments.



Next Page > Hide TOC


© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.