buoy.widget
Class BComboBox

java.lang.Object
  extended by buoy.event.EventSource
      extended by buoy.widget.Widget
          extended by buoy.widget.BComboBox

public class BComboBox
extends Widget

A BComboBox is a Widget that displays a popup menu with a list of objects for the user to select. Typically the objects are Strings, but other types of objects can be used as well. Optionally, the combo box may be made editable, so the user may type a value directly rather than selecting one from the list. This allows arbitrary values to be entered, not just standard ones in the list.

BComboBox provides methods for adding and removing objects in the list. Alternatively, you can set a ComboBoxModel to provide more complex behaviors.

In addition to the event types generated by all Widgets, BComboBoxes generate the following event types:

Author:
Peter Eastman

Constructor Summary
BComboBox()
          Create a new uneditable BComboBox containing no objects.
BComboBox(java.util.Collection contents)
          Create a new uneditable BComboBox containing the objects in a Collection.
BComboBox(javax.swing.ComboBoxModel model)
          Create a new uneditable BComboBox whose contents are determined by a ComboBoxModel.
BComboBox(java.lang.Object[] contents)
          Create a new uneditable BComboBox containing the objects in an array.
 
Method Summary
 void add(int index, java.lang.Object o)
          Add an object at specified position in the middle of the list.
 void add(java.lang.Object o)
          Add an object to the end of the list.
 javax.swing.JComboBox getComponent()
          Get the java.awt.Component corresponding to this Widget.
 java.lang.Object getItem(int index)
          Get the item at a specific position in the list.
 int getItemCount()
          Get the number of items in the combo box's list.
 javax.swing.ComboBoxModel getModel()
          Get the ComboBoxModel which controls the contents of this BComboBox.
 int getPreferredVisibleRows()
          Get the preferred number of rows which should be visible in the popup menu without using a scrollbar.
 int getSelectedIndex()
          Get the index of the selected item.
 java.lang.Object getSelectedValue()
          Get the current value which has been selected from the list or, if this is an editable combo box, typed into the box.
 boolean isEditable()
          Get whether this combo box is editable, allowing the user to type in values other than those in the popup list.
 void remove(int index)
          Remove an object from the list.
 void removeAll()
          Remove all objects from the list.
 void replace(int index, java.lang.Object o)
          Replace the object at a specified position in the list with a new one.
 void setContents(java.util.Collection c)
          Set the contents of the list to the objects in a Collection.
 void setContents(java.lang.Object[] o)
          Set the contents of the list to the objects in an array.
 void setEditable(boolean editable)
          Set whether this combo box is editable, allowing the user to type in values other than those in the popup list.
 void setModel(javax.swing.ComboBoxModel model)
          Set the ComboBoxModel which controls the contents of this BComboBox.
 void setPreferredVisibleRows(int rows)
          Get the preferred number of rows which should be visible in the popup menu without using a scrollbar.
 void setSelectedIndex(int index)
          Select the item with the specified index.
 void setSelectedValue(java.lang.Object value)
          Set the value shown in the combo box.
 
Methods inherited from class buoy.widget.Widget
addEventLink, dispatchEvent, getBackground, getBounds, getCursor, getFont, getMaximumSize, getMinimumSize, getName, getParent, getPreferredSize, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible
 
Methods inherited from class buoy.event.EventSource
addEventLink, addEventLink, removeEventLink
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BComboBox

public BComboBox()
Create a new uneditable BComboBox containing no objects.


BComboBox

public BComboBox(java.lang.Object[] contents)
Create a new uneditable BComboBox containing the objects in an array.


BComboBox

public BComboBox(java.util.Collection contents)
Create a new uneditable BComboBox containing the objects in a Collection. The objects will be added in the order they are returned by the Collection's Iterator.


BComboBox

public BComboBox(javax.swing.ComboBoxModel model)
Create a new uneditable BComboBox whose contents are determined by a ComboBoxModel.

Method Detail

getComponent

public javax.swing.JComboBox getComponent()
Description copied from class: Widget
Get the java.awt.Component corresponding to this Widget.

Overrides:
getComponent in class Widget

isEditable

public boolean isEditable()
Get whether this combo box is editable, allowing the user to type in values other than those in the popup list.


setEditable

public void setEditable(boolean editable)
Set whether this combo box is editable, allowing the user to type in values other than those in the popup list.


setContents

public void setContents(java.lang.Object[] o)
Set the contents of the list to the objects in an array. This completely replaces the contents of the list, removing any objects that were previously in it.

Parameters:
o - the objects to put in the combo box's list

setContents

public void setContents(java.util.Collection c)
Set the contents of the list to the objects in a Collection. This completely replaces the contents of the list, removing any objects that were previously in it. The objects will be added in the order they are returned by the Collection's Iterator.

Parameters:
c - the objects to put in the combo box's list

getModel

public javax.swing.ComboBoxModel getModel()
Get the ComboBoxModel which controls the contents of this BComboBox.


setModel

public void setModel(javax.swing.ComboBoxModel model)
Set the ComboBoxModel which controls the contents of this BComboBox.


add

public void add(java.lang.Object o)
Add an object to the end of the list.

Parameters:
o - the object to add

add

public void add(int index,
                java.lang.Object o)
Add an object at specified position in the middle of the list.

Parameters:
index - the position at which to add the object
o - the object to add

replace

public void replace(int index,
                    java.lang.Object o)
Replace the object at a specified position in the list with a new one.

Parameters:
index - the position at which to set the object
o - the new object to add

remove

public void remove(int index)
Remove an object from the list.

Parameters:
index - the position from which to remove the object

removeAll

public void removeAll()
Remove all objects from the list.


getItemCount

public int getItemCount()
Get the number of items in the combo box's list.


getItem

public java.lang.Object getItem(int index)
Get the item at a specific position in the list.


getPreferredVisibleRows

public int getPreferredVisibleRows()
Get the preferred number of rows which should be visible in the popup menu without using a scrollbar.


setPreferredVisibleRows

public void setPreferredVisibleRows(int rows)
Get the preferred number of rows which should be visible in the popup menu without using a scrollbar.


getSelectedIndex

public int getSelectedIndex()
Get the index of the selected item. If this is an editable combo box and the current value is not in the list, this returns -1.


setSelectedIndex

public void setSelectedIndex(int index)
Select the item with the specified index.


getSelectedValue

public java.lang.Object getSelectedValue()
Get the current value which has been selected from the list or, if this is an editable combo box, typed into the box.


setSelectedValue

public void setSelectedValue(java.lang.Object value)
Set the value shown in the combo box. If this combo box is not editable and the specified value is not a member of the list, this will have no effect.



Written by Peter Eastman.