A BList is a Widget that displays a list of objects for the user to select. Typically the objects are
Strings, but other types of objects can be used as well. It supports both single and multiple selection
modes. There are methods for adding and removing objects in the list. Alternatively, you can set a
ListModel to provide more complex behaviors.
BList does not provide scrolling automatically. Normally, it is used inside a BScrollPane.
In addition to the event types generated by all Widgets, BLists generate the following event types:
add
public void add(Object o)
Add an object to the end of the list.
If you have set a custom model for this list, either by passing it to the constructor or by calling
setModel(), this method has no effect.
add
public void add(int index,
Object o)
Add an object at specified position in the middle of the list.
If you have set a custom model for this list, either by passing it to the constructor or by calling
setModel(), this method has no effect.
index
- the position at which to add the objecto
- the object to add
clearSelection
public void clearSelection()
Deselect all objects in the list.
getItem
public Object getItem(int index)
Get the item at a specific position in the list.
getItemCount
public int getItemCount()
Get the number of items in the list.
getMaximumSize
public Dimension getMaximumSize()
Get the largest size at which this Widget can reasonably be drawn. When a WidgetContainer lays out
its contents, it will attempt never to make this Widget larger than its maximum size.
- getMaximumSize in interface Widget
getModel
public ListModel getModel()
Get the ListModel which controls the contents of this BList.
getPreferredVisibleRows
public int getPreferredVisibleRows()
Get the preferred number of rows which should be visible without using a scrollbar.
getSelectedIndex
public int getSelectedIndex()
Get the index of the first selected object, or -1 if nothing is selected.
getSelectedIndices
public int[] getSelectedIndices()
Get the indices of all selected objects, in increasing order.
getSelectedValue
public Object getSelectedValue()
Get the first selected object, or null if nothing is selected.
getSelectedValues
public Object[] getSelectedValues()
Get an array of all selected objects, in order of increasing index.
isMultipleSelectionEnabled
public boolean isMultipleSelectionEnabled()
Determine whether this list allows multiple objects to be selected.
isSelected
public boolean isSelected(int index)
Determine whether a particular object in the list is selected.
remove
public void remove(int index)
Remove an object from the list.
If you have set a custom model for this list, either by passing it to the constructor or by calling
setModel(), this method has no effect.
index
- the position from which to remove the object
removeAll
public void removeAll()
Remove all objects from the list.
If you have set a custom model for this list, either by passing it to the constructor or by calling
setModel(), this method has no effect.
replace
public void replace(int index,
Object o)
Replace the object at a specified position in the list with a new one.
If you have set a custom model for this list, either by passing it to the constructor or by calling
setModel(), this method has no effect.
index
- the position at which to set the objecto
- the new object to add
scrollToItem
public void scrollToItem(int index)
Scroll the BList's parent BScrollPane to ensure that a particular list entry is visible. If
the parent is not a BScrollPane, the results of calling this method are undefined, but usually
it will have no effect at all.
setContents
public void setContents(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.
If you have set a custom model for this list, either by passing it to the constructor or by calling
setModel(), this method has no effect.
c
- the objects to put in the list
setContents
public void setContents(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.
If you have set a custom model for this list, either by passing it to the constructor or by calling
setModel(), this method has no effect.
setModel
public void setModel(ListModel model)
Set the ListModel which controls the contents of this BList.
setMultipleSelectionEnabled
public void setMultipleSelectionEnabled(boolean multiple)
Set whether this list should allow multiple objects to be selected.
setPreferredVisibleRows
public void setPreferredVisibleRows(int rows)
Set the preferred number of rows which should be visible without using a scrollbar.
setSelected
public void setSelected(int index,
boolean selected)
Set whether a particular object should be selected.