How Panels Work
A panel is a special kind of window, typically serving an auxiliary function in an application. The
NSPanel subclass of
NSWindow adds a few special behaviors to windows in support of the role panels play:
By default panels are not released when they’re closed, because they’re usually lightweight and often reused.
Onscreen panels, except for alert dialogs, are removed from the screen when the application isn’t active and are restored when the application again becomes active. This reduces screen clutter.
Panels can become the key window, but they cannot become the main window.
If a panel is the key window and has a close button, it closes itself when the user presses the Escape key.
In addition to these automatic behaviors, the
NSPanel class allows you to configure certain other behaviors common to some kinds of panels:
You can prevent a panel from becoming the key window unless the user clicks in a view that responds to typing. This prevents the key window from shifting to the panel unnecessarily. The
setBecomesKeyOnlyIfNeeded:method controls this behavior.
Palettes and similar panels can be made to float above standard windows and other panels. This prevents them from being covered and keeps them readily available to the user. The
setFloatingPanel:method controls this behavior.
A panel can be made to receive mouse and keyboard events even when another window or panel is being run modally or in a modal session. This permits actions in the panel to affect the modal window or panel. The
setWorksWhenModal:method controls this behavior. See “How Modal Windows Work” for more information on modal windows and panels.