public class ListBox extends AbstractListComponent
ListBox component: a selection component which displays selection items in a list. May be configured to allow the
selection of one item at a time, or to allow the selection of multiple items at one time. Does not support child components.ACTION_LISTENERS_CHANGED_PROPERTY, DEFAULT_LIST_CELL_RENDERER, INPUT_ACTION, LIST_CELL_RENDERER_CHANGED_PROPERTY, LIST_DATA_CHANGED_PROPERTY, LIST_MODEL_CHANGED_PROPERTY, PROPERTY_ACTION_COMMAND, PROPERTY_BORDER, PROPERTY_DISABLED_BACKGROUND, PROPERTY_DISABLED_BORDER, PROPERTY_DISABLED_FONT, PROPERTY_DISABLED_FOREGROUND, PROPERTY_HEIGHT, PROPERTY_INSETS, PROPERTY_ROLLOVER_BACKGROUND, PROPERTY_ROLLOVER_ENABLED, PROPERTY_ROLLOVER_FONT, PROPERTY_ROLLOVER_FOREGROUND, PROPERTY_TOOL_TIP_TEXT, PROPERTY_WIDTH, SELECTION_CHANGED_PROPERTY, SELECTION_MODEL_CHANGED_PROPERTYCHILD_VISIBLE_CHANGED_PROPERTY, CHILDREN_CHANGED_PROPERTY, ENABLED_CHANGED_PROPERTY, FOCUS_NEXT_ID_CHANGED_PROPERTY, FOCUS_PREVIOUS_ID_CHANGED_PROPERTY, LAYOUT_DIRECTION_CHANGED_PROPERTY, LOCALE_CHANGED_PROPERTY, PROPERTY_BACKGROUND, PROPERTY_FONT, PROPERTY_FOREGROUND, PROPERTY_LAYOUT_DATA, STYLE_CHANGED_PROPERTY, STYLE_NAME_CHANGED_PROPERTY, VISIBLE_CHANGED_PROPERTY| Constructor and Description |
|---|
ListBox()
Creates an empty
ListBox. |
ListBox(ListModel model)
Creates a
ListBox visualizing the specified model. |
ListBox(ListModel model,
ListSelectionModel selectionModel)
Creates a
ListBox visualizing the specified
ListModel and describing selections using the specified
ListSelectionModel. |
ListBox(java.lang.Object[] itemArray)
Creates a
ListBox with a DefaultListModel
that initially contains the specified array of items. |
| Modifier and Type | Method and Description |
|---|---|
int |
getMaxSelectedIndex()
Returns the maximum selected index.
|
int |
getMinSelectedIndex()
Returns the minimum selected index.
|
int[] |
getSelectedIndices()
Returns all selected indices.
|
java.lang.Object |
getSelectedValue()
Returns the selected item.
|
java.lang.Object[] |
getSelectedValues()
Returns all selected items.
|
int |
getSelectionMode()
Returns the selection mode.
|
boolean |
isSelectedIndex(int index)
Determines whether an index is selected.
|
void |
setSelectedIndex(int index)
Selects only the given index.
|
void |
setSelectedIndex(int index,
boolean selected)
Sets the selection state of the given index.
|
void |
setSelectedIndices(int[] indices)
Selects the specified indices, deselecting any other indices.
|
void |
setSelectionMode(int newValue)
Sets the selection mode.
|
addActionListener, getActionCommand, getBorder, getCellRenderer, getDisabledBackground, getDisabledBorder, getDisabledFont, getDisabledForeground, getHeight, getInsets, getModel, getRolloverBackground, getRolloverFont, getRolloverForeground, getSelectionModel, getToolTipText, getWidth, hasActionListeners, isRolloverEnabled, isValidChild, processInput, removeActionListener, setActionCommand, setBorder, setCellRenderer, setDisabledBackground, setDisabledBorder, setDisabledFont, setDisabledForeground, setHeight, setInsets, setModel, setRolloverBackground, setRolloverEnabled, setRolloverFont, setRolloverForeground, setSelectionModel, setToolTipText, setWidthadd, add, addPropertyChangeListener, addPropertyChangeListener, dispose, firePropertyChange, get, getApplicationInstance, getBackground, getComponent, getComponent, getComponentCount, getComponents, getEventListenerList, getFocusNextId, getFocusPreviousId, getFont, getForeground, getId, getIndex, getLayoutData, getLayoutDirection, getLocale, getLocalStyle, getParent, getRenderId, getRenderIndexedProperty, getRenderIndexedProperty, getRenderLocale, getRenderProperty, getRenderProperty, getStyle, getStyleName, getVisibleComponent, getVisibleComponentCount, getVisibleComponents, hasEventListenerList, indexOf, init, isAncestorOf, isEnabled, isFocusTraversalParticipant, isRegistered, isRenderEnabled, isRenderVisible, isValidParent, isVisible, remove, remove, removeAll, removePropertyChangeListener, removePropertyChangeListener, set, setBackground, setComponents, setEnabled, setFocusNextId, setFocusPreviousId, setFocusTraversalParticipant, setFont, setForeground, setId, setIndex, setLayoutData, setLayoutDirection, setLocale, setRenderId, setStyle, setStyleName, setVisible, validate, verifyInput, visibleIndexOfpublic ListBox()
ListBox.
A DefaultListModel will be created.
A DefaultListSelectionModel will be created and used
to describe selections.public ListBox(ListModel model)
ListBox visualizing the specified model.
A DefaultListSelectionModel will be created and used
to describe selections.model - the initial modelpublic ListBox(ListModel model, ListSelectionModel selectionModel)
ListBox visualizing the specified
ListModel and describing selections using the specified
ListSelectionModel.model - the initial modelselectionModel - the initial selection modelpublic ListBox(java.lang.Object[] itemArray)
ListBox with a DefaultListModel
that initially contains the specified array of items.
A DefaultListSelectionModel will be created and used
to describe selections.itemArray - an array of items that will initially populate
this ListBoxpublic int getMaxSelectedIndex()
public int getMinSelectedIndex()
public int[] getSelectedIndices()
public java.lang.Object getSelectedValue()
public java.lang.Object[] getSelectedValues()
public int getSelectionMode()
ListSelectionModel.SINGLE_SELECTION: only one
list element may be selected.ListSelectionModel.MULTIPLE_SELECTION:
multiple list elements may be selected.public boolean isSelectedIndex(int index)
index - the indexpublic void setSelectedIndex(int index)
index - the indexpublic void setSelectedIndex(int index,
boolean selected)
index - the indexselected - the selection statepublic void setSelectedIndices(int[] indices)
indices - the indices to be selectedpublic void setSelectionMode(int newValue)
newValue - the selection mode, one of the following values:
ListSelectionModel.SINGLE_SELECTION: only one
list element may be selected.ListSelectionModel.MULTIPLE_SELECTION:
multiple list elements may be selected.