public class Choice extends Component implements ItemSelectable, Serializable, Accessible
| Modifier and Type | Class and Description |
|---|---|
protected class |
Choice.AccessibleAWTChoice
This class provides accessibility support for the
combo box.
|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategyBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
Choice()
Initializes a new instance of
Choice. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(String item)
Adds the specified item to this choice box.
|
void |
addItem(String item)
Adds the specified item to this choice box.
|
void |
addItemListener(ItemListener listener)
Adds the specified listener to the list of registered listeners for
this object.
|
void |
addNotify()
Creates the native peer for this object.
|
int |
countItems()
Deprecated.
This method is deprecated in favor of
getItemCount. |
AccessibleContext |
getAccessibleContext()
Gets the AccessibleContext associated with this
Choice. |
String |
getItem(int index)
Returns the item at the specified index in the list.
|
int |
getItemCount()
Returns the number of items in the list.
|
ItemListener[] |
getItemListeners()
Returns all registered item listeners.
|
<T extends EventListener> |
getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as FooListeners
upon this Choice.
|
int |
getSelectedIndex()
Returns the index of the selected item.
|
String |
getSelectedItem()
Returns the currently selected item, or null if no item is
selected.
|
Object[] |
getSelectedObjects()
Returns an array with one row containing the selected item.
|
void |
insert(String item,
int index)
Inserts an item into this Choice.
|
protected String |
paramString()
Returns a debugging string for this object.
|
protected void |
processEvent(AWTEvent event)
Processes this event by invoking
processItemEvent() if the
event is an instance of ItemEvent, otherwise the event
is passed to the superclass. |
protected void |
processItemEvent(ItemEvent event)
Processes item event by dispatching to any registered listeners.
|
void |
remove(int index)
Removes the item at the specified index from the choice box.
|
void |
remove(String item)
Removes the specified item from the choice box.
|
void |
removeAll()
Removes all of the objects from this choice box.
|
void |
removeItemListener(ItemListener listener)
Removes the specified listener from the list of registered listeners for
this object.
|
void |
select(int index)
Forces the item at the specified index to be selected.
|
void |
select(String item)
Forces the named item to be selected.
|
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, firePropertyChange, firePropertyChange, firePropertyChange, 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, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validatepublic Choice()
Choice.HeadlessException - If GraphicsEnvironment.isHeadless()
returns truepublic int getItemCount()
public int countItems()
getItemCount.public String getItem(int index)
index - The index into the list to return the item from.ArrayIndexOutOfBoundsException - If the index is invalid.public void add(String item)
item - The item to add.NullPointerException - If the item's value is nullpublic void addItem(String item)
add(String) instead.item - The item to add.NullPointerException - If the item's value is equal to nullpublic void insert(String item, int index)
item - The item to add.index - The index at which the item should be inserted.IllegalArgumentException - If index is less than 0public void remove(String item)
item - The item to remove.IllegalArgumentException - If the specified item doesn't exist.public void remove(int index)
index - The index of the item to remove.IndexOutOfBoundsException - If the index is not valid.public void removeAll()
public String getSelectedItem()
public Object[] getSelectedObjects()
getSelectedObjects in interface ItemSelectablepublic int getSelectedIndex()
public void select(int index)
index - The index of the row to make selected.IllegalArgumentException - If the specified index is invalid.public void select(String item)
item - The item to be selected.IllegalArgumentException - If the specified item does not exist.public void addNotify()
addNotify in class ComponentComponent.isDisplayable(),
Component.removeNotify()public void addItemListener(ItemListener listener)
addItemListener in interface ItemSelectablelistener - The listener to add.public void removeItemListener(ItemListener listener)
removeItemListener in interface ItemSelectablelistener - The listener to remove.protected void processEvent(AWTEvent event)
processItemEvent() if the
event is an instance of ItemEvent, otherwise the event
is passed to the superclass.processEvent in class Componentevent - The event to process.Component.processComponentEvent(ComponentEvent),
Component.processFocusEvent(FocusEvent),
Component.processKeyEvent(KeyEvent),
Component.processMouseEvent(MouseEvent),
Component.processMouseMotionEvent(MouseEvent),
Component.processInputMethodEvent(InputMethodEvent),
Component.processHierarchyEvent(HierarchyEvent),
Component.processMouseWheelEvent(MouseWheelEvent)protected void processItemEvent(ItemEvent event)
event - The event to process.protected String paramString()
paramString in class Componentpublic <T extends EventListener> T[] getListeners(Class<T> listenerType)
getListeners in class ComponentlistenerType - the class of listeners to filter (null
not permitted).ClassCastException - If listenerType doesn't specify a class or
interface that implements java.util.EventListener.Component.getComponentListeners(),
Component.getFocusListeners(),
Component.getHierarchyListeners(),
Component.getHierarchyBoundsListeners(),
Component.getKeyListeners(),
Component.getMouseListeners(),
Component.getMouseMotionListeners(),
Component.getMouseWheelListeners(),
Component.getInputMethodListeners(),
Component.getPropertyChangeListeners()public ItemListener[] getItemListeners()
public AccessibleContext getAccessibleContext()
Choice.
The context is created, if necessary.getAccessibleContext in interface AccessiblegetAccessibleContext in class Component