java::awt::Choice Class Reference

Inheritance diagram for java::awt::Choice:

Inheritance graph
java::awt::Componentjava::lang::Objectjava::lang::Interfacejava::lang::Syncjava::awt::event::ComponentSourcejava::awt::event::FocusSourcejava::awt::event::HierarchySourcejava::awt::event::KeySourcejava::awt::event::MouseSourcejava::awt::event::PaintSourcejava::util::PropertyChangeSourcejava::awt::event::ItemSourcejava::lang::Lockjava::lang::ScopeAdapterjava::awt::image::ImageObserverjava::util::EventSourcejava::awt::ItemSelectable
[legend]
Collaboration diagram for java::awt::Choice:

Collaboration graph
java::awt::Componentjava::lang::Objectjava::lang::Interfacejava::lang::ObjectRefjava::lang::Syncjava::awt::event::ComponentSourcejava::awt::event::FocusSourcejava::awt::event::HierarchySourcejava::awt::event::KeySourcejava::awt::event::MouseSourcejava::awt::event::PaintSourcejava::util::PropertyChangeSourcejava::awt::event::ItemSourcejava::lang::Lockjava::lang::ScopeAdapterjava::lang::Comparablejava::awt::image::ImageObserverjava::util::EventSourcejava::util::Collectionjava::awt::ItemSelectablejava::util::LinkedListjava::util::AbstractSequentialListjava::util::AbstractListjava::util::AbstractCollectionjava::util::List
[legend]

List of all members.


Detailed Description

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:


<blockquote>
 Choice ColorChooser = new Choice();
 ColorChooser.add("Green");
 ColorChooser.add("Red");
 ColorChooser.add("Blue");
 
</blockquote>

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

Choice-1.gif

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.

Version:
1.83 01/23/03
Author:
Sami Shaio

Arthur van Hoff

Since:
JDK1.0

Public Member Functions

 Choice ()
 Creates a new choice menu.
virtual jint getItemCount () const
 Returns the number of items in this Choice menu.
virtual String getItem (jint index) const
 Gets the string at the specified index in this Choice menu.
virtual Ref< ListgetItems () const
 Gets the items in the Choice menu.
virtual void add (const String &item, jint index=-1)
 Adds the specified item to the the Choice menu at the position indicated by the index.
virtual void removeAll ()
 Removes all items from this component.
virtual void remove (const String &item)
 Removes the first occurrence of an item from the component.
virtual void remove (jint position)
 Remove the item at the specified position from this component.
virtual jint getSelectedIndex () const
 Gets the index of the selected item on the component,.
virtual String getSelectedItem () const
 Gets the selected item on this component.
virtual Ref< ListgetSelectedObjects () const
 Returns the selected items or null if no items are selected.
virtual void select (jint index)
 Selects the item at the specified index in the component.
virtual void select (const String &item)
 Sets the selected item in this Choice menu to be the item whose name is equal to the specified string.
virtual String toString () const
 Returns a string representation of this component and its values.

Protected Attributes

 REGISTER_MEMBERS

Constructor & Destructor Documentation

java::awt::Choice::Choice (  ) 

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 select methods.

Exceptions:
HeadlessException if GraphicsEnvironment.isHeadless() returns true
See also:
java.awt.GraphicsEnvironment::isHeadless

select(int)

select(java.lang.String)


Member Function Documentation

virtual jint java::awt::Choice::getItemCount (  )  const [virtual]

Returns the number of items in this Choice menu.

Returns:
the number of items in this Choice menu
See also:
getItem
Since:
JDK1.1

virtual String java::awt::Choice::getItem ( jint  index  )  const [virtual]

Gets the string at the specified index in this Choice menu.

Parameters:
index the index at which to begin
See also:
getItemCount

virtual Ref<List> java::awt::Choice::getItems (  )  const [virtual]

Gets the items in the Choice menu.

Returns:
a string array containing items of the component
See also:
select

deselect

isIndexSelected

Since:
JDK1.1

virtual void java::awt::Choice::add ( const String item,
jint  index = -1 
) [virtual]

Adds the specified item to the the Choice menu at the position indicated by the index.

The index is zero-based. If the value of the index is less than zero, or if the value of the index is greater than or equal to the number of items in the component, then the item is added to the end of the component.

Parameters:
item the item to be added; if this parameter is null then the item is treated as an empty string, ""
index the position at which to add the item
Since:
JDK1.1

virtual void java::awt::Choice::removeAll (  )  [virtual]

Removes all items from this component.

See also:
remove

delItems

Since:
JDK1.1

virtual void java::awt::Choice::remove ( const String item  )  [virtual]

Removes the first occurrence of an item from the component.

Parameters:
item the item to remove from the component
Exceptions:
IllegalArgumentException if the item doesn't exist in the component
Since:
JDK1.1

virtual void java::awt::Choice::remove ( jint  position  )  [virtual]

Remove the item at the specified position from this component.

Parameters:
position the index of the item to delete
See also:
add(String, int)
Since:
JDK1.1
Exceptions:
ArrayIndexOutOfBoundsException if the position is less than 0 or greater than getItemCount()-1

virtual jint java::awt::Choice::getSelectedIndex (  )  const [virtual]

Gets the index of the selected item on the component,.

Returns:
the index of the selected item, or -1 if no item is selected, or if more that one item is selected
See also:
select

deselect

isIndexSelected

virtual String java::awt::Choice::getSelectedItem (  )  const [virtual]

Gets the selected item on this component.

Returns:
the selected item on the component, or null if no item is selected
See also:
select

deselect

isIndexSelected

virtual Ref<List> java::awt::Choice::getSelectedObjects (  )  const [virtual]

Returns the selected items or null if no items are selected.

Implements java::awt::ItemSelectable.

virtual void java::awt::Choice::select ( jint  index  )  [virtual]

Selects the item at the specified index in the component.

Note that this method should be primarily used to initially select an item in this component. Programmatically calling this method will not trigger an ItemEvent. The only way to trigger an ItemEvent is by user interaction.

Parameters:
index the position of the item to select
See also:
getSelectedItem

deselect

isIndexSelected

virtual void java::awt::Choice::select ( const String item  )  [virtual]

Sets the selected item in this Choice menu to be the item whose name is equal to the specified string.

If more than one item matches (is equal to) the specified string, the one with the smallest index is selected.

Note that this method should be primarily used to initially select an item in this component. Programmatically calling this method will not trigger an ItemEvent. The only way to trigger an ItemEvent is by user interaction.

Parameters:
str the specified string
See also:
getSelectedItem

getSelectedIndex

virtual String java::awt::Choice::toString (  )  const [virtual]

Returns a string representation of this component and its values.

Returns:
a string representation of this component
Since:
JDK1.0

Reimplemented from java::awt::Component.


Member Data Documentation

java::awt::Choice::REGISTER_MEMBERS [protected]

Reimplemented from java::awt::Component.


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:55:55 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3