java.awt

Class Choice

Implemented Interfaces:
Accessible, ImageObserver, ItemSelectable, MenuContainer, Serializable

public class Choice
extends Component
implements ItemSelectable, Serializable, Accessible

This class implements a drop down choice list.
See Also:
Serialized Form

Nested Class Summary

protected class
Choice.AccessibleAWTChoice
This class provides accessibility support for the combo box.

Nested classes/interfaces inherited from class java.awt.Component

Component.AccessibleAWTComponent, 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()
Initializes a new instance of Choice.

Method Summary

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.
extends EventListener> T[] getListeners(Class listenerType)
Returns an array of all the objects currently registered as FooListeners upon this Choice.
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.
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.

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, 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, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, 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, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, 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, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Choice

public Choice()
Initializes a new instance of Choice.
Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() returns true

Method Details

add

public void add(String item)
Adds the specified item to this choice box.
Parameters:
item - The item to add.
Throws:
NullPointerException - If the item's value is null
Since:
1.1

addItem

public void addItem(String item)
Adds the specified item to this choice box. This method is oboslete since Java 2 platform 1.1. Please use add(String) instead.
Parameters:
item - The item to add.
Throws:
NullPointerException - If the item's value is equal to null

addItemListener

public void addItemListener(ItemListener listener)
Adds the specified listener to the list of registered listeners for this object.
Specified by:
addItemListener in interface ItemSelectable
Parameters:
listener - The listener to add.

addNotify

public void addNotify()
Creates the native peer for this object.
Overrides:
addNotify in interface Component

countItems

public int countItems()

Deprecated. This method is deprecated in favor of getItemCount.

Returns the number of items in the list.
Returns:
The number of items in the list.

extends EventListener> T[] getListeners

public extends EventListener> T[] getListeners(Class listenerType)
Returns an array of all the objects currently registered as FooListeners upon this Choice. FooListeners are registered using the addFooListener method.
Overrides:
extends EventListener> T[] getListeners in interface Component
Throws:
ClassCastException - If listenerType doesn't specify a class or interface that implements java.util.EventListener.
Since:
1.3

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this Choice. The context is created, if necessary.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface Component
Returns:
the associated context

getItem

public String getItem(int index)
Returns the item at the specified index in the list.
Parameters:
index - The index into the list to return the item from.
Throws:
ArrayIndexOutOfBoundsException - If the index is invalid.

getItemCount

public int getItemCount()
Returns the number of items in the list.
Returns:
The number of items in the list.

getItemListeners

public ItemListener[] getItemListeners()
Returns all registered item listeners.
Since:
1.4

getSelectedIndex

public int getSelectedIndex()
Returns the index of the selected item.
Returns:
The index of the selected item.

getSelectedItem

public String getSelectedItem()
Returns the currently selected item, or null if no item is selected.
Returns:
The currently selected item.

getSelectedObjects

public Object[] getSelectedObjects()
Returns an array with one row containing the selected item.
Specified by:
getSelectedObjects in interface ItemSelectable
Returns:
An array containing the selected item.

insert

public void insert(String item,
                   int index)
Inserts an item into this Choice. Existing items are shifted upwards. If the new item is the only item, then it is selected. If the currently selected item is shifted, then the first item is selected. If the currently selected item is not shifted, then it remains selected.
Parameters:
item - The item to add.
index - The index at which the item should be inserted.
Throws:
IllegalArgumentException - If index is less than 0

paramString

protected String paramString()
Returns a debugging string for this object.
Overrides:
paramString in interface Component
Returns:
A debugging string for this object.

processEvent

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.
Overrides:
processEvent in interface Component
Parameters:
event - The event to process.

processItemEvent

protected void processItemEvent(ItemEvent event)
Processes item event by dispatching to any registered listeners.
Parameters:
event - The event to process.

remove

public void remove(int index)
Removes the item at the specified index from the choice box.
Parameters:
index - The index of the item to remove.
Throws:
IndexOutOfBoundsException - If the index is not valid.

remove

public void remove(String item)
Removes the specified item from the choice box.
Parameters:
item - The item to remove.
Throws:
IllegalArgumentException - If the specified item doesn't exist.

removeAll

public void removeAll()
Removes all of the objects from this choice box.

removeItemListener

public void removeItemListener(ItemListener listener)
Removes the specified listener from the list of registered listeners for this object.
Specified by:
removeItemListener in interface ItemSelectable
Parameters:
listener - The listener to remove.

select

public void select(int index)
Forces the item at the specified index to be selected.
Parameters:
index - The index of the row to make selected.
Throws:
IllegalArgumentException - If the specified index is invalid.

select

public void select(String item)
Forces the named item to be selected.
Parameters:
item - The item to be selected.
Throws:
IllegalArgumentException - If the specified item does not exist.

Choice.java -- Java choice button widget. Copyright (C) 1999, 2000, 2001, 2002, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.