org.eclipse.swt.widgets
Class Combo

public class Combo
extends Composite
Instances of this class are controls that allow the user to choose an item from a list of items, or optionally enter a new value by typing it into an editable text field. Often, Combos are used in the same place where a single selection List widget could be used but space is limited. A Combo takes less space than a List widget and shows similar information.

Note: Since Combos can contain both a list and an editable text field, it is possible to confuse methods which access one versus the other (compare for example, clearSelection() and deselectAll()). The API documentation is careful to indicate either "the receiver's list" or the "the receiver's text field" to distinguish between the two cases.

Note that although this class is a subclass of Composite, it does not make sense to add children to it, or set a layout on it.

Styles:
DROP_DOWN, READ_ONLY, SIMPLE
Events:
DefaultSelection, Modify, Selection

Note: Only one of the styles DROP_DOWN and SIMPLE may be specified.

IMPORTANT: This class is not intended to be subclassed.

SinceNot specified.
VersionNot specified.
AuthorNot specified.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
Field Summary
static int LIMIT
the operating system limit for the number of characters that the text field in an instance of this class can hold
Fields inherited from org.eclipse.swt.widgetsControl
Constructor Summary
Combo( Composite parent, int style )
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
Method Summary
void add( String string )
Adds the argument to the end of the receiver's list.
void add( String string, int index )
Adds the argument to the receiver's list at the given zero-relative index.
void addModifyListener( ModifyListener listener )
Adds the listener to the collection of listeners who will be notified when the receiver's text is modified, by sending it one of the messages defined in the ModifyListener interface.
void addSelectionListener( SelectionListener listener )
Adds the listener to the collection of listeners who will be notified when the receiver's selection changes, by sending it one of the messages defined in the SelectionListener interface.
void addVerifyListener( VerifyListener listener )
Adds the listener to the collection of listeners who will be notified when the receiver's text is verified, by sending it one of the messages defined in the VerifyListener interface.
protected void checkSubclass()
No description provided.
void clearSelection()
Sets the selection in the receiver's text field to an empty selection starting just before the first character.
Point computeSize( int wHint, int hHint, boolean changed )
No description provided.
void copy()
Copies the selected text.
void cut()
Cuts the selected text.
void deselect( int index )
Deselects the item at the given zero-relative index in the receiver's list.
void deselectAll()
Deselects all selected items in the receiver's list.
String getItem( int index )
Returns the item at the given, zero-relative index in the receiver's list.
int getItemCount()
Returns the number of items contained in the receiver's list.
int getItemHeight()
Returns the height of the area which would be used to display one of the items in the receiver's list.
String[] getItems()
Returns a (possibly empty) array of Strings which are the items in the receiver's list.
int getOrientation()
Returns the orientation of the receiver.
Point getSelection()
Returns a Point whose x coordinate is the character position representing the start of the selection in the receiver's text field, and whose y coordinate is the character position representing the end of the selection.
int getSelectionIndex()
Returns the zero-relative index of the item which is currently selected in the receiver's list, or -1 if no item is selected.
String getText()
Returns a string containing a copy of the contents of the receiver's text field, or an empty string if there are no contents.
int getTextHeight()
Returns the height of the receivers's text field.
int getTextLimit()
Returns the maximum number of characters that the receiver's text field is capable of holding.
int getVisibleItemCount()
Gets the number of items that are visible in the drop down portion of the receiver's list.
int indexOf( String string )
Searches the receiver's list starting at the first item (index 0) until an item is found that is equal to the argument, and returns the index of that item.
int indexOf( String string, int start )
Searches the receiver's list starting at the given, zero-relative index until an item is found that is equal to the argument, and returns the index of that item.
void paste()
Pastes text from clipboard.
void remove( int index )
Removes the item from the receiver's list at the given zero-relative index.
void remove( int start, int end )
Removes the items from the receiver's list which are between the given zero-relative start and end indices (inclusive).
void remove( String string )
Searches the receiver's list starting at the first item until an item is found that is equal to the argument, and removes that item from the list.
void removeAll()
Removes all of the items from the receiver's list and clear the contents of receiver's text field.
void removeModifyListener( ModifyListener listener )
Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.
void removeSelectionListener( SelectionListener listener )
Removes the listener from the collection of listeners who will be notified when the receiver's selection changes.
void removeVerifyListener( VerifyListener listener )
Removes the listener from the collection of listeners who will be notified when the control is verified.
void select( int index )
Selects the item at the given zero-relative index in the receiver's list.
void setFont( Font font )
No description provided.
void setItem( int index, String string )
Sets the text of the item in the receiver's list at the given zero-relative index to the string argument.
void setItems( String [] items )
Sets the receiver's list to be the given array of items.
void setOrientation( int orientation )
Sets the orientation of the receiver, which must be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
void setSelection( Point selection )
Sets the selection in the receiver's text field to the range specified by the argument whose x coordinate is the start of the selection and whose y coordinate is the end of the selection.
void setText( String string )
Sets the contents of the receiver's text field to the given string.
void setTextLimit( int limit )
Sets the maximum number of characters that the receiver's text field is capable of holding to be the argument.
void setVisibleItemCount( int count )
Sets the number of items that are visible in the drop down portion of the receiver's list.
Methods inherited from org.eclipse.swt.widgetsControl
Methods inherited from org.eclipse.swt.graphicsDrawable
LIMIT
public static int LIMIT
the operating system limit for the number of characters that the text field in an instance of this class can hold
Wiki javadoc Use textile entry format.
Add your comments here.
Combo
public Combo ( Composite parent, int style )
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

Parameters
TypeNameDescription
Composite parent a composite control which will be the parent of the new instance (cannot be null)
int style the style of control to construct
Wiki javadoc Use textile entry format.
Add your comments here.
add
public void add ( String string )
Adds the argument to the end of the receiver's list.
Parameters
TypeNameDescription
String string the new item
Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
add
public void add ( String string, int index )
Adds the argument to the receiver's list at the given zero-relative index.

Note: To add an item at the end of the list, use the result of calling getItemCount() as the index or use add(String).

Parameters
TypeNameDescription
String string the new item
int index the index for the item
Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
addModifyListener
public void addModifyListener ( ModifyListener listener )
Adds the listener to the collection of listeners who will be notified when the receiver's text is modified, by sending it one of the messages defined in the ModifyListener interface.
Parameters
TypeNameDescription
ModifyListener listener the listener which should be notified
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
addSelectionListener
public void addSelectionListener ( SelectionListener listener )
Adds the listener to the collection of listeners who will be notified when the receiver's selection changes, by sending it one of the messages defined in the SelectionListener interface.

widgetSelected is called when the combo's list selection changes. widgetDefaultSelected is typically called when ENTER is pressed the combo's text area.

Parameters
TypeNameDescription
SelectionListener listener the listener which should be notified
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
addVerifyListener
public void addVerifyListener ( VerifyListener listener )
Adds the listener to the collection of listeners who will be notified when the receiver's text is verified, by sending it one of the messages defined in the VerifyListener interface.
Since: 3.1
Parameters
TypeNameDescription
VerifyListener listener the listener which should be notified
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
checkSubclass
protected void checkSubclass ( )
No description provided.
Overrides method in Composite
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
clearSelection
public void clearSelection ( )
Sets the selection in the receiver's text field to an empty selection starting just before the first character. If the text field is editable, this has the effect of placing the i-beam at the start of the text.

Note: To clear the selected items in the receiver's list, use deselectAll().

Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
computeSize
public Point computeSize ( int wHint, int hHint, boolean changed )
No description provided.
Overrides method in Composite
Parameters
TypeNameDescription
int wHint No description provided.
int hHint No description provided.
boolean changed No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
copy
public void copy ( )
Copies the selected text.

The current selection is copied to the clipboard.

Since: 2.1
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
cut
public void cut ( )
Cuts the selected text.

The current selection is first copied to the clipboard and then deleted from the widget.

Since: 2.1
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
deselect
public void deselect ( int index )
Deselects the item at the given zero-relative index in the receiver's list. If the item at the index was already deselected, it remains deselected. Indices that are out of range are ignored.
Parameters
TypeNameDescription
int index the index of the item to deselect
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
deselectAll
public void deselectAll ( )
Deselects all selected items in the receiver's list.

Note: To clear the selection in the receiver's text field, use clearSelection().

Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
getItem
public String getItem ( int index )
Returns the item at the given, zero-relative index in the receiver's list. Throws an exception if the index is out of range.
Parameters
TypeNameDescription
int index the index of the item to return
Wiki javadoc Use textile entry format.
Add your comments here.
getItemCount
public int getItemCount ( )
Returns the number of items contained in the receiver's list.
Wiki javadoc Use textile entry format.
Add your comments here.
getItemHeight
public int getItemHeight ( )
Returns the height of the area which would be used to display one of the items in the receiver's list.
Wiki javadoc Use textile entry format.
Add your comments here.
getItems
public String[] getItems ( )
Returns a (possibly empty) array of Strings which are the items in the receiver's list.

Note: This is not the actual structure used by the receiver to maintain its list of items, so modifying the array will not affect the receiver.

Wiki javadoc Use textile entry format.
Add your comments here.
getOrientation
public int getOrientation ( )
Returns the orientation of the receiver.
Since: 2.1.2
Wiki javadoc Use textile entry format.
Add your comments here.
getSelection
public Point getSelection ( )
Returns a Point whose x coordinate is the character position representing the start of the selection in the receiver's text field, and whose y coordinate is the character position representing the end of the selection. An "empty" selection is indicated by the x and y coordinates having the same value.

Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget.

Wiki javadoc Use textile entry format.
Add your comments here.
getSelectionIndex
public int getSelectionIndex ( )
Returns the zero-relative index of the item which is currently selected in the receiver's list, or -1 if no item is selected.
Wiki javadoc Use textile entry format.
Add your comments here.
getText
public String getText ( )
Returns a string containing a copy of the contents of the receiver's text field, or an empty string if there are no contents.
Wiki javadoc Use textile entry format.
Add your comments here.
getTextHeight
public int getTextHeight ( )
Returns the height of the receivers's text field.
Wiki javadoc Use textile entry format.
Add your comments here.
getTextLimit
public int getTextLimit ( )
Returns the maximum number of characters that the receiver's text field is capable of holding. If this has not been changed by setTextLimit(), it will be the constant Combo.LIMIT.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
getVisibleItemCount
public int getVisibleItemCount ( )
Gets the number of items that are visible in the drop down portion of the receiver's list.

Note: This operation is a hint and is not supported on platforms that do not have this concept.

Since: 3.0
Wiki javadoc Use textile entry format.
Add your comments here.
indexOf
public int indexOf ( String string )
Searches the receiver's list starting at the first item (index 0) until an item is found that is equal to the argument, and returns the index of that item. If no item is found, returns -1.
Parameters
TypeNameDescription
String string the search item
Wiki javadoc Use textile entry format.
Add your comments here.
indexOf
public int indexOf ( String string, int start )
Searches the receiver's list starting at the given, zero-relative index until an item is found that is equal to the argument, and returns the index of that item. If no item is found or the starting index is out of range, returns -1.
Parameters
TypeNameDescription
String string the search item
int start the zero-relative index at which to begin the search
Wiki javadoc Use textile entry format.
Add your comments here.
paste
public void paste ( )
Pastes text from clipboard.

The selected text is deleted from the widget and new text inserted from the clipboard.

Since: 2.1
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
remove
public void remove ( int index )
Removes the item from the receiver's list at the given zero-relative index.
Parameters
TypeNameDescription
int index the index for the item
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
remove
public void remove ( int start, int end )
Removes the items from the receiver's list which are between the given zero-relative start and end indices (inclusive).
Parameters
TypeNameDescription
int start the start of the range
int end the end of the range
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
remove
public void remove ( String string )
Searches the receiver's list starting at the first item until an item is found that is equal to the argument, and removes that item from the list.
Parameters
TypeNameDescription
String string the item to remove
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
removeAll
public void removeAll ( )
Removes all of the items from the receiver's list and clear the contents of receiver's text field.

Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
removeModifyListener
public void removeModifyListener ( ModifyListener listener )
Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.
Parameters
TypeNameDescription
ModifyListener listener the listener which should no longer be notified
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
removeSelectionListener
public void removeSelectionListener ( SelectionListener listener )
Removes the listener from the collection of listeners who will be notified when the receiver's selection changes.
Parameters
TypeNameDescription
SelectionListener listener the listener which should no longer be notified
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
removeVerifyListener
public void removeVerifyListener ( VerifyListener listener )
Removes the listener from the collection of listeners who will be notified when the control is verified.
Since: 3.1
Parameters
TypeNameDescription
VerifyListener listener the listener which should no longer be notified
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
select
public void select ( int index )
Selects the item at the given zero-relative index in the receiver's list. If the item at the index was already selected, it remains selected. Indices that are out of range are ignored.
Parameters
TypeNameDescription
int index the index of the item to select
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
setFont
public void setFont ( Font font )
No description provided.
Overrides method in Control
Parameters
TypeNameDescription
Font font No description provided.
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
setItem
public void setItem ( int index, String string )
Sets the text of the item in the receiver's list at the given zero-relative index to the string argument. This is equivalent to removing the old item at the index, and then adding the new item at that index.
Parameters
TypeNameDescription
int index the index for the item
String string the new text for the item
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
setItems
public void setItems ( String [] items )
Sets the receiver's list to be the given array of items.
Parameters
TypeNameDescription
String [] items the array of items
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
setOrientation
public void setOrientation ( int orientation )
Sets the orientation of the receiver, which must be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.

Since: 2.1.2
Parameters
TypeNameDescription
int orientation new orientation style
Returns void No description provided.
Wiki javadoc Use textile entry format.

e

setSelection
public void setSelection ( Point selection )
Sets the selection in the receiver's text field to the range specified by the argument whose x coordinate is the start of the selection and whose y coordinate is the end of the selection.
Parameters
TypeNameDescription
Point selection a point representing the new selection start and end
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
setText
public void setText ( String string )
Sets the contents of the receiver's text field to the given string.

Note: The text field in a Combo is typically only capable of displaying a single line of text. Thus, setting the text to a string containing line breaks or other special characters will probably cause it to display incorrectly.

Parameters
TypeNameDescription
String string the new text
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
setTextLimit
public void setTextLimit ( int limit )
Sets the maximum number of characters that the receiver's text field is capable of holding to be the argument.

To reset this value to the default, use setTextLimit(Combo.LIMIT). Specifying a limit value larger than Combo.LIMIT sets the receiver's limit to Combo.LIMIT.

Parameters
TypeNameDescription
int limit new text limit
Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
setVisibleItemCount
public void setVisibleItemCount ( int count )
Sets the number of items that are visible in the drop down portion of the receiver's list.

Note: This operation is a hint and is not supported on platforms that do not have this concept.

Since: 3.0
Parameters
TypeNameDescription
int count the new number of items to be visible
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.