java.awt
Class Choice

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Choice
All Implemented Interfaces:
Accessible, ImageObserver, ItemSelectable, MenuContainer, Serializable
public class Choice
extends Component
implements ItemSelectable, Accessible

The Choice class presents a pop-up menu of choices. The current choice is displayed as the title of the menu.

The following code example produces a pop-up menu:


 Choice ColorChooser = new Choice();
 ColorChooser.add("Green");
 ColorChooser.add("Red");
 ColorChooser.add("Blue");
 

After this choice menu has been added to a panel, it appears as follows in its normal state:

In the picture, "Green" is the current choice. Pushing the mouse button down on the object causes a menu to appear with the current choice highlighted.

Some native platforms do not support arbitrary resizing of Choice components and the behavior of setSize()/getSize() is bound by such limitations. Native GUI Choice components' size are often bound by such attributes as font size and length of items contained within the Choice.

Since:
JDK1.0
See Also:
Serialized Form

 

Nested Class Summary

protected  class Choice.AccessibleAWTChoice
    This class implements accessibility support for the Choice class.
 
Nested classes inherited from class java.awt.Component
Component.BltBufferStrategy, Component.FlipBufferStrategy
 

 

Field Summary

 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 

 

Constructor Summary

Choice()
    Creates a new choice menu.
 

 

Method Summary

 void add(String item)
    Adds an item to this Choice menu.
 void addItem(String item)
    Obsolete as of Java 2 platform v1.1.
 void addItemListener(ItemListener l)
    Adds the specified item listener to receive item events from this Choice menu.
 void addNotify()
    Creates the Choice's peer.
 int countItems()
    Deprecated. As of JDK version 1.1, replaced by getItemCount().
 AccessibleContext getAccessibleContext()
    Gets the AccessibleContext associated with this Choice.
 String getItem(int index)
    Gets the string at the specified index in this Choice menu.
 int getItemCount()
    Returns the number of items in this Choice menu.
 ItemListener[] getItemListeners()
    Returns an array of all the item listeners registered on this choice.
 EventListener[] getListeners(Class listenerType)
    Returns an array of all the objects currently registered as FooListeners upon this Choice.
 int getSelectedIndex()
    Returns the index of the currently selected item.
 String getSelectedItem()
    Gets a representation of the current choice as a string.
 Object[] getSelectedObjects()
    Returns an array (length 1) containing the currently selected item.
 void insert(String item, int index)
    Inserts the item into this choice at the specified position.
protected  String paramString()
    Returns a string representing the state of this Choice menu.
protected  void processEvent(AWTEvent e)
    Processes events on this choice.
protected  void processItemEvent(ItemEvent e)
    Processes item events occurring on this Choice menu by dispatching them to any registered ItemListener objects.
 void remove(int position)
    Removes an item from the choice menu at the specified position.
 void remove(String item)
    Removes the first occurrence of item from the Choice menu.
 void removeAll()
    Removes all items from the choice menu.
 void removeItemListener(ItemListener l)
    Removes the specified item listener so that it no longer receives item events from this Choice menu.
 void select(int pos)
    Sets the selected item in this Choice menu to be the item at the specified position.
 void select(String str)
    Sets the selected item in this Choice menu to be the item whose name is equal to the specified string.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle,