Inherits from: NSButton : NSControl : NSView : NSResponder : NSObject
Conforms to: NSCoding
(NSResponder)
NSObject (NSObject)
Declared in: AppKit/NSPopUpButton.h
Interface Builder |
selectedItem | Returns the currently selected item. |
indexOfSelectedItem | Returns an integer identifying the currently selected item. |
titleOfSelectedItem | Returns a string identifying the currently selected item. |
The NSPopUpButton class defines objects that implement the pop-up and pull-down lists of the OpenStep graphical user interface. You normally create an NSPopUpButton using Interface Builder.
When configured to display a pop-up list, an NSPopUpButton contains a number of options and usually displays the option that was last selected. A pop-up list is often used for selecting items from a small- to medium-sized set of options (like the zoom factor for a document window). It's a useful alternative to a matrix of radio buttons or an NSBrowser or NSTableView when screen space is at a premium; a zoom factor pop-up can easily fit next to a scroll bar at the bottom of a window, for example.
When configured to display a pull-down list, an NSPopUpButton is generally used for selecting commands in a very specific context. You can think of a pull-down list as a compact form of menu. A pull-down list's display isn't affected by the user's actions, and a pull-down list usually displays the first item in the list. When the commands only make sense in the context of a particular display, a pull-down list can be used in that display to keep the related actions nearby and to keep them out of the way when that display isn't visible.
The items in the pop-up list or pull-down list (referred to simply as a list in this class description) are objects that conform to the NSMenuItem interface. Thus, you can send any message defined in that protocol to any item in the list.
Although the NSPopUpButton class defines an initialization method and methods that set up the list created by this class, you usually don't invoke these methods in your program. The typical way to create an NSPopUpButton is to use Interface Builder. You can define the NSPopUpButton's target and action, as well as the targets and actions of each item in the NSPopUpButton's list, programmatically or through Interface Builder. The NSPopUpButton methods you use most often are the methods that tell you which item is selected.
- Initializing an NSPopUpButton
- initWithFrame:pullsDown:
- Setting the type of list
- setPullsDown
- pullsDown
- setAutoenablesItems
- autoenablesItems
- Inserting and deleting Items
- addItemWithTitle
- addItemsWithTitles
- insertItemAtIndex
- removeAllItems
- removeItemWithTitle
- removeItemAtIndex
- Getting the user's selection
- selectedItem
- titleOfSelectedItem
- indexOfSelectedItem
- Setting the current selection
- selectItem
- selectItemAtIndex
- selectItemWithTitle
- Getting menu items
- numberOfItems
- itemArray
- itemAtIndex
- itemTitleAtIndex
- itemTitles
- itemWithTitle
- lastItem
- Getting the indices of menu items
- indexOfItem
- indexOfItemWithTag
- indexOfItemWithTitle
- indexOfItemWithRepresentedObject
- indexOfItemWithTargetAndAction
- Setting the cell edge to pop out from in restricted situations
- preferredEdge
- setPreferredEdge
- Setting the font
- setFont:
- Setting the title
- setTitle
- Setting the state
- synchronizeTitleAndSelectedItem
public NSPopUpButton(NSRect aNSRect)
public NSPopUpButton(NSRect frameRect, boolean aFlag)
true
,
the receiver is initialized to operate as a pull-down list; otherwise,
it operates as a pop-up list.See Also: - pullsDown, - setPullsDown:
public void addItem(String title)
See Also: insertItemAtIndex, removeItemWithTitle, setTitle
public void addItemsWithTitles(NSArray itemTitles)
See Also: insertItemAtIndex, removeAllItems, removeItemWithTitle
public boolean autoenablesItems()
false
to the NSPopUpButton.
See the NSMenuActionResponder interfacei for more information on
autoenabling menu items.See Also: setAutoenablesItems
public int indexOfItem(NSMenuItem anObject)
public int indexOfItemWithRepresentedObject(Object anObject)
public int indexOfItemWithTag(int tag)
public int indexOfItemWithTargetAndAction(Object target, NSSelector actionSelector)
null
,
the index of the first menu item in the pop-up list that has target target is
returned. If no menu item matching the above criteria is found,
-1 is returned. This method invokes the method of the same name
of its NSPopUpButtonCell.public int indexOfItemWithTitle(String title)
public int indexOfSelectedItem()
See Also: selectedItem, titleOfSelectedItem
public void insertItemAtIndex(String title, int index)
If an item with the name title already exists in the list, it's removed and the new one is added. This essentially moves title to a new position. If you want to move an item, it's better to invoke removeItemWithTitle explicitly and then send this method.
See Also: addItemWithTitle, addItemsWithTitles, indexOfItemWithTitle, removeItemWithTitle
public NSArray itemArray()
See Also: itemAtIndex, insertItemAtIndex, removeItemAtIndex
public NSMenuItem itemAtIndex(int index)
null
.See Also: itemWithTitle, lastItem
public String itemTitleAtIndex(int index)
See Also: itemTitles
public NSArray itemTitles()
See Also: itemTitleAtIndex, itemWithTitle, numberOfItems
public NSMenuItem itemWithTitle(String title)
null
.See Also: addItemWithTitle, selectItemWithTitle, itemAtIndex, indexOfItemWithTitle
public NSMenuItem lastItem()
See Also: itemAtIndex
public NSMenu menu()
public int numberOfItems()
See Also: lastItem
public int preferredEdge()
See Also: setPreferredEdge
public boolean pullsDown()
true
if
the receiver is configured as a pull-down list or false
if
it's configured as a pop-up list.See Also: setPullsDown
public void removeAllItems()
See Also: numberOfItems, removeItemAtIndex, removeItemWithTitle
public void removeItemAtIndex(int index)
See Also: insertItemAtIndex, removeAllItems, removeItemWithTitle
public void removeItemWithTitle(String title)
See Also: addItemWithTitle, removeAllItems, removeItemAtIndex
public NSMenuItem selectedItem()
null
. It is possible
for a pull-down list's selected item to be its first item.public void selectItem(NSMenuItem aNSMenuItem)
null
,
all items in the list are deselected (this is a technique for obtaining
a pop-up list with no items selected).public void selectItemAtIndex(int index)
See Also: indexOfSelectedItem
public void selectItemWithTitle(String title)
See Also: indexOfItemWithTitle, addItemWithTitle, setTitle
public void setAutoenablesItems(boolean flag)
false
as
the value for flag. See the NSMenuActionResponder interface for more
information on autoenabling menu items.See Also: autoenablesItems
public void setMenu(NSMenu menu)
public void setPreferredEdge(int edge)
See Also: preferredEdge
public void setPullsDown(boolean flag)
true
,
the receiver is configured as a pull-down list. If flag is false
,
the receiver is configured as a pop-up list.See Also: initWithFrame:pullsDown:pullsDown
public void setTitle(String aString)
public void synchronizeTitleAndSelectedItem()
See Also: itemArray
public String titleOfSelectedItem()
See Also: indexOfSelectedItem
Posted when the NSPopUpButton receives a mouse-down event; that is, when the user is about to select an item from the list. This notification contains a notification object but no userInfo dictionary. The notification object is the selected NSPopUpButton.