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
.
Modifier and Type | Class and Description |
---|---|
protected class | Choice.
This class implements accessibility support for the
|
Modifier and Type | Field and Description |
---|---|
private static final String | |
private int | choiceSerializedDataVersion
Serialized data version. |
pack-priv transient ItemListener | |
private static int | |
pack-priv Vector | pItems
The items for the |
pack-priv int | selectedIndex
The index of the current choice for this |
private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability.
|
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public void | |
public void | |
public synchronized void | addItemListener(ItemListener
the item listener l)Implements java. Choice menu.
|
public void | |
pack-priv String | constructComponentName()
Overrides java. |
public int | Returns: the number of items in thisChoice menu
Deprecated
As of JDK version 1.1,
replaced by
Returns the number of items in this getItemCount() .
Choice menu.
|
pack-priv boolean | |
public AccessibleContext | Returns: anAccessibleAWTChoice that serves as the
AccessibleContext of this Choice Overrides java. Implements javax. AccessibleContext associated with this
Choice .
|
public String | Returns: the item at the specified indexthe index at which to begin index)Gets the string at the specified index in this
|
public int | Returns: the number of items in thisChoice menuReturns the number of items in this |
pack-priv final String | |
public synchronized ItemListener[] | Returns: all of this choice'sItemListener s
or an empty array if no item
listeners are currently registeredReturns an array of all the item listeners registered on this choice. |
public <T extends EventListener> T[] | Returns: an array of all objects registered asFooListener s on this choice,
or an empty array if no such
listeners have been addedthe type of listeners requested; this parameter
should specify an interface that descends from
listenerType)java.util.EventListener Overrides java. FooListener s
upon this Choice .
|
public int | Returns: the index of the currently selected item, or -1 if nothing is currently selectedReturns the index of the currently selected item. |
public synchronized String | Returns: a string representation of the currently selected item in this choice menuGets a representation of the current choice as a string. |
public synchronized Object[] | getSelectedObjects()
Implements java. |
private static native void | |
public void | |
private void | insertNoInvalidate(String
the item to be added item, int the new item position index)Inserts an item to this |
protected String | Returns: the parameter string of thisChoice menuOverrides java. Choice
menu.
|
protected void | processEvent(AWTEvent
the event e)Overrides java. |
protected void | processItemEvent(ItemEvent
the item event e)Processes item events occurring on this |
private void | readObject(ObjectInputStream
the s)ObjectInputStream to readHides java. ObjectInputStream and if it
isn't null adds a listener to receive
item events fired by the Choice item.
|
public void | |
public void | remove(int
the position of the item position)Removes an item from the choice menu at the specified position. |
public void | |
public synchronized void | removeItemListener(ItemListener
the item listener l)Implements java. Choice menu.
|
private void | removeNoInvalidate(int
the position of the item position)Removes an item from the |
public synchronized void | select(int
the position of the selected item pos)Sets the selected item in this |
public synchronized void | |
private void | writeObject(ObjectOutputStream
the s)
Writes default serializable fields to stream.
ObjectOutputStream to write |
base | back to summary |
---|---|
private static final String base |
choiceSerializedDataVersion | back to summary |
---|---|
private int choiceSerializedDataVersion Serialized data version. |
itemListener | back to summary |
---|---|
pack-priv transient ItemListener itemListener |
nameCounter | back to summary |
---|---|
private static int nameCounter |
pItems | back to summary |
---|---|
pack-priv Vector<String> pItems The items for the |
selectedIndex | back to summary |
---|---|
pack-priv int selectedIndex The index of the current choice for this
|
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.1 for interoperability. |
Choice | back to summary |
---|---|
public Choice() throws HeadlessException Creates a new choice menu. The menu initially has no items in it.
By default, the first item added to the choice menu becomes the
selected item, until a different selection is made by the user
by calling one of the
|
add | back to summary |
---|---|
public void add(String item) Adds an item to this
|
addItem | back to summary |
---|---|
public void addItem(String item) Obsolete as of Java 2 platform v1.1. Please use the
Adds an item to this
|
addItemListener | back to summary |
---|---|
public synchronized void addItemListener(ItemListener l) Implements java. Adds the specified item listener to receive item events from
this Refer to AWT Threading Issues for details on AWT's threading model.
|
addNotify | back to summary |
---|---|
public void addNotify() Overrides java. Creates the
|
constructComponentName | back to summary |
---|---|
pack-priv String constructComponentName() Overrides java. Constructs a name for this component. Called by
|
countItems | back to summary |
---|---|
public int countItems()
Deprecated As of JDK version 1.1,
replaced by Returns the number of items in this
|
eventEnabled | back to summary |
---|---|
pack-priv boolean eventEnabled(AWTEvent e) Overrides java. |
getAccessibleContext | back to summary |
---|---|
public AccessibleContext getAccessibleContext() Overrides java. Implements javax. Gets the
|
getItem | back to summary |
---|---|
public String getItem(int index) Gets the string at the specified index in this
|
getItemCount | back to summary |
---|---|
public int getItemCount() Returns the number of items in this
|
getItemImpl | back to summary |
---|---|
pack-priv final String getItemImpl(int index) |
getItemListeners | back to summary |
---|---|
public synchronized ItemListener[] getItemListeners() Returns an array of all the item listeners registered on this choice.
|
getListeners | back to summary |
---|---|
public <T extends EventListener> T[] getListeners(Class<T> listenerType) Overrides java. Returns an array of all the objects currently registered
as
You can specify the ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));If no such listeners exist, this method returns an empty array.
|
getSelectedIndex | back to summary |
---|---|
public int getSelectedIndex() Returns the index of the currently selected item. If nothing is selected, returns -1.
|
getSelectedItem | back to summary |
---|---|
public synchronized String getSelectedItem() Gets a representation of the current choice as a string.
|
getSelectedObjects | back to summary |
---|---|
public synchronized Object[] getSelectedObjects() Implements java. Returns an array (length 1) containing the currently selected
item. If this choice has no items, returns
|
initIDs | back to summary |
---|---|
private static native void initIDs() Hides java. Initialize JNI field and method IDs |
insert | back to summary |
---|---|
public void insert(String item, int index) Inserts the item into this choice at the specified position.
Existing items at an index greater than or equal to
If the item is the first one being added to the choice, then the item becomes selected. Otherwise, if the selected item was one of the items shifted, the first item in the choice becomes the selected item. If the selected item was no among those shifted, it remains the selected item.
|
insertNoInvalidate | back to summary |
---|---|
private void insertNoInvalidate(String item, int index) Inserts an item to this
|
paramString | back to summary |
---|---|
protected String paramString() Overrides java. Returns a string representing the state of this
|
processEvent | back to summary |
---|---|
protected void processEvent(AWTEvent e) Overrides java. Processes events on this choice. If the event is an
instance of Note that if the event parameter is
|
processItemEvent | back to summary |
---|---|
protected void processItemEvent(ItemEvent e) Processes item events occurring on this This method is not called unless item events are enabled for this component. Item events are enabled when one of the following occurs:
Note that if the event parameter is
|
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException, HeadlessException Hides java. Reads the
|
remove | back to summary |
---|---|
public void remove(String item) Removes the first occurrence of
|
remove | back to summary |
---|---|
public void remove(int position) Removes an item from the choice menu at the specified position. If the item being removed is the currently selected item, then the first item in the choice becomes the selected item. Otherwise, the currently selected item remains selected (and the selected index is updated accordingly).
|
removeAll | back to summary |
---|---|
public void removeAll() Removes all items from the choice menu.
|
removeItemListener | back to summary |
---|---|
public synchronized void removeItemListener(ItemListener l) Implements java. Removes the specified item listener so that it no longer receives
item events from this Refer to AWT Threading Issues for details on AWT's threading model.
|
removeNoInvalidate | back to summary |
---|---|
private void removeNoInvalidate(int position) Removes an item from the
|
select | back to summary |
---|---|
public synchronized void select(int pos) Sets the selected item in this Note that this method should be primarily used to
initially select an item in this component.
Programmatically calling this method will not trigger
an
|
select | back to summary |
---|---|
public synchronized void select(String str) Sets the selected item in this Note that this method should be primarily used to
initially select an item in this component.
Programmatically calling this method will not trigger
an
|
writeObject | back to summary |
---|---|
private void writeObject(ObjectOutputStream s) throws IOException Hides java. Writes default serializable fields to stream. Writes
a list of serializable
|
Choice
class. It provides an implementation of the
Java Accessibility API appropriate to choice user-interface elements.
Modifier and Type | Field and Description |
---|---|
private static final long | serialVersionUID
Hides java. |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true if the action was performed; otherwise false.zero-based index of actions i)Implements javax. |
public AccessibleAction | Returns: this objectOverrides javax. |
public int | Returns: the zero-based number of Actions in this objectImplements javax. |
public String | Returns: a String description of the actionzero-based index of the actions i)Implements javax. |
public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides java. |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.3 for interoperability. |
AccessibleAWTChoice | back to summary |
---|---|
public AccessibleAWTChoice() Constructor for |
doAccessibleAction | back to summary |
---|---|
public boolean doAccessibleAction(int i) Implements javax. Perform the specified Action on the object
|
getAccessibleAction | back to summary |
---|---|
public AccessibleAction getAccessibleAction() Overrides javax. Get the AccessibleAction associated with this object. In the implementation of the Java Accessibility API for this class, return this object, which is responsible for implementing the AccessibleAction interface on behalf of itself.
|
getAccessibleActionCount | back to summary |
---|---|
public int getAccessibleActionCount() Implements javax. Returns the number of accessible actions available in this object If there are more than one, the first one is considered the "default" action of the object.
|
getAccessibleActionDescription | back to summary |
---|---|
public String getAccessibleActionDescription(int i) Implements javax. Returns a description of the specified action of the object.
|
getAccessibleRole | back to summary |
---|---|
public AccessibleRole getAccessibleRole() Overrides java. Get the role of this object.
|