javax.swing

Class JList

public class JList extends JComponent implements Accessible, Scrollable

This class is a facade over three separate objects: {@link javax.swing.ListModel}, {@link javax.swing.ListSelectionModel} and {@link javax.swing.plaf.ListUI}. The facade represents a unified "list" concept, with independently replacable (possibly client-provided) models for its contents and its current selection. In addition, each element in the list is rendered via a strategy class {@link javax.swing.ListCellRenderer}.

Lists have many properties, some of which are stored in this class while others are delegated to the list's model or selection. The following properties are available:

Property Stored inBound?
accessibleContext list no
anchorSelectionIndex selectionno
cellRenderer list yes
dragEnabled list no
firstVisibleIndex list no
fixedCellHeight list yes
fixedCellWidth list yes
lastVisibleIndex list no
layoutOrientation list yes
leadSelectionIndex selectionno
maxSelectionIndex selectionno
minSelectionIndex selectionno
model list yes
opaque list no
preferredScrollableViewportSizelist no
prototypeCellValue list yes
scrollableTracksViewportHeight list no
scrollableTracksViewportWidth list no
selectedIndex selectionno
selectedIndices selectionno
selectedValue model no
selectedValues model no
selectionBackground list yes
selectionEmpty selectionno
selectionForeground list yes
selectionMode selectionno
selectionModel list yes
UI list yes
UIClassID list no
valueIsAdjusting list no
visibleRowCount list no
Nested Class Summary
protected classJList.AccessibleJList
Provides accessibility support for JList.
Field Summary
static intHORIZONTAL_WRAP
Constant value used in "layoutOrientation" property.
static intVERTICAL
Constant value used in "layoutOrientation" property.
static intVERTICAL_WRAP
Constant value used in "layoutOrientation" property.
Constructor Summary
JList()
Creates a new JList object.
JList(Object[] items)
Creates a new JList object.
JList(Vector<?> items)
Creates a new JList object.
JList(ListModel model)
Creates a new JList object.
Method Summary
voidaddListSelectionListener(ListSelectionListener listener)
Adds a {@link ListSelectionListener} to the listener list for this list.
voidaddSelectionInterval(int anchor, int lead)
Adds the specified interval to the current selection.
voidclearSelection()
Clears the current selection.
protected ListSelectionModelcreateSelectionModel()
Creates the default ListSelectionModel.
voidensureIndexIsVisible(int i)
Scrolls this list to make the specified cell visible.
protected voidfireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
Fire a {@link ListSelectionEvent} to all the registered ListSelectionListeners.
AccessibleContextgetAccessibleContext()
intgetAnchorSelectionIndex()
Returns the index of the anchor item in the current selection, or -1 if there is no anchor item.
RectanglegetCellBounds(int index0, int index1)
Returns the bounds of the rectangle that encloses both list cells with index0 and index1.
ListCellRenderergetCellRenderer()
Gets the value of the {@link #cellRenderer} property.
booleangetDragEnabled()
Return the value of the dragEnabled property.
intgetFirstVisibleIndex()
Returns the list index of the upper left or upper right corner of the visible rectangle of this list, depending on the {@link Component#getComponentOrientation} property.
intgetFixedCellHeight()
Gets the value of the {@link #fixedCellHeight} property.
intgetFixedCellWidth()
Gets the value of the {@link #fixedCellWidth} property.
intgetLastVisibleIndex()
Returns the list index of the lower right or lower left corner of the visible rectangle of this list, depending on the {@link Component#getComponentOrientation} property.
intgetLayoutOrientation()
Returns the layout orientation, which will be one of {@link #VERTICAL}, {@link #VERTICAL_WRAP} and {@link #HORIZONTAL_WRAP}.
intgetLeadSelectionIndex()
Returns the index of the lead item in the current selection, or -1 if there is no lead item.
ListSelectionListener[]getListSelectionListeners()
Returns an array of all ListSelectionListeners subscribed to this list.
intgetMaxSelectionIndex()
Returns the highest item index in the current selection, or -1 if there is no selection.
intgetMinSelectionIndex()
Returns the lowest item index in the current selection, or -1 if there is no selection.
ListModelgetModel()
Gets the value of the {@link #model} property.
intgetNextMatch(String prefix, int startIndex, Position.Bias direction)
Returns the index of the next list element (beginning at startIndex and moving in the specified direction through the list, looping around if necessary) that starts with prefix (ignoring case).
DimensiongetPreferredScrollableViewportSize()
Returns a size indicating how much space this list would like to consume, when contained in a scrollable viewport.
ObjectgetPrototypeCellValue()
Returns the current value of the {@link #prototypeCellValue} property.
intgetScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)

Return the number of pixels the list must scroll in order to move a "block" of the list into the provided visible rectangle.

booleangetScrollableTracksViewportHeight()
Gets the value of the scrollableTracksViewportWidth property.
booleangetScrollableTracksViewportWidth()
Gets the value of the scrollableTracksViewportWidth property.
intgetScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)

Return the number of pixels the list must scroll in order to move a "unit" of the list into the provided visible rectangle.

intgetSelectedIndex()
Returns the minimum index of an element in the list which is currently selected.
int[]getSelectedIndices()
Returns the indices of values in the {@link #model} property which are selected.
ObjectgetSelectedValue()
Returns the first value in the list's {@link #model} property which is selected, according to the list's {@link #selectionModel} property.
Object[]getSelectedValues()
Returns all the values in the list's {@link #model} property which are selected, according to the list's {@link #selectionModel} property.
ColorgetSelectionBackground()
Gets the value of the {@link #selectionBackground} property.
ColorgetSelectionForeground()
Gets the value of the {@link #selectionForeground} property.
intgetSelectionMode()
Returns the selection mode for the list (one of: {@link ListSelectionModel#SINGLE_SELECTION}, {@link ListSelectionModel#SINGLE_INTERVAL_SELECTION} and {@link ListSelectionModel#MULTIPLE_INTERVAL_SELECTION}).
ListSelectionModelgetSelectionModel()
Returns the selection model for the {@link JList} component.
ListUIgetUI()
Gets the value of the UI property.
StringgetUIClassID()
Return the class identifier for the list's UI property.
booleangetValueIsAdjusting()
Returns the valueIsAdjusting flag from the list's selection model.
intgetVisibleRowCount()
Gets the value of the {@link #visibleRowCount} property.
PointindexToLocation(int index)
Returns location of the cell located at the specified index in the list.
booleanisSelectedIndex(int a)
Indicates whether the list element at a given index value is currently selected.
booleanisSelectionEmpty()
Returns true if the model's selection is empty, otherwise false.
intlocationToIndex(Point location)
Returns index of the cell to which specified location is closest to.
protected StringparamString()
Returns a string describing the attributes for the JList component, for use in debugging.
voidremoveListSelectionListener(ListSelectionListener listener)
Removes a {@link ListSelectionListener} from the listener list for this list.
voidremoveSelectionInterval(int index0, int index1)
Removes the specified interval from the current selection.
voidsetCellRenderer(ListCellRenderer renderer)
Sets the value of the {@link #getCellRenderer} property.
voidsetDragEnabled(boolean enabled)
Set the dragEnabled property.
voidsetFixedCellHeight(int h)
Sets the value of the {@link #fixedCellHeight} property.
voidsetFixedCellWidth(int w)
Sets the value of the {@link #fixedCellWidth} property.
voidsetLayoutOrientation(int orientation)
Sets the layout orientation (this is a bound property with the name 'layoutOrientation').
voidsetListData(Object[] listData)
Sets the {@link #model} property of the list to a new anonymous {@link AbstractListModel} subclass which accesses the provided Object array directly.
voidsetListData(Vector<?> listData)
Sets the {@link #model} property of the list to a new anonymous {@link AbstractListModel} subclass which accesses the provided vector directly.
voidsetModel(ListModel model)
Sets the value of the {@link #model} property.
voidsetPrototypeCellValue(Object obj)

Set the {@link #prototypeCellValue} property.

voidsetSelectedIndex(int a)
Adds the interval [a,a] to the set of selections managed by this list's {@link #selectionModel} property.
voidsetSelectedIndices(int[] a)
For each element a[i] of the provided array a, calls {@link #setSelectedIndex} on a[i].
voidsetSelectedValue(Object obj, boolean scroll)
Sets the selection to cover only the specified value, if it exists in the model.
voidsetSelectionBackground(Color c)
Sets the value of the {@link #selectionBackground} property.
voidsetSelectionForeground(Color c)
Sets the value of the {@link #selectionForeground} property.
voidsetSelectionInterval(int anchor, int lead)
Sets the current selection to the items in the specified range (inclusive).
voidsetSelectionMode(int a)
Sets the list's "selectionMode" property, which simply mirrors the same property on the list's {@link #selectionModel} property.
voidsetSelectionModel(ListSelectionModel model)
Sets the value of the {@link #selectionModel} property.
voidsetUI(ListUI ui)
Sets the value of the UI property.
voidsetValueIsAdjusting(boolean isAdjusting)
Sets the valueIsAdjusting flag in the list's selection model.
voidsetVisibleRowCount(int vc)
Sets the value of the {@link #visibleRowCount} property.
voidupdateUI()
Calls {@link #setUI} with the {@link ListUI} subclass returned from calling {@link UIManager#getUI}.

Field Detail

HORIZONTAL_WRAP

public static final int HORIZONTAL_WRAP
Constant value used in "layoutOrientation" property. This value means that cells are laid out in multiple columns "newspaper style", filling horizontally first, then vertically.

VERTICAL

public static final int VERTICAL
Constant value used in "layoutOrientation" property. This value means that cells are laid out in a single vertical column. This is the default.

VERTICAL_WRAP

public static final int VERTICAL_WRAP
Constant value used in "layoutOrientation" property. This value means that cells are laid out in multiple columns "newspaper style", filling vertically first, then horizontally.

Constructor Detail

JList

public JList()
Creates a new JList object.

JList

public JList(Object[] items)
Creates a new JList object.

Parameters: items the initial list items.

JList

public JList(Vector<?> items)
Creates a new JList object.

Parameters: items the initial list items.

JList

public JList(ListModel model)
Creates a new JList object.

Parameters: model a model containing the list items (null not permitted).

Throws: IllegalArgumentException if model is null.

Method Detail

addListSelectionListener

public void addListSelectionListener(ListSelectionListener listener)
Adds a {@link ListSelectionListener} to the listener list for this list. The listener will be called back with a {@link ListSelectionEvent} any time the list's {@link #selectionModel} property changes. The source of such events will be the JList, not the selection model.

Parameters: listener The new listener to add

addSelectionInterval

public void addSelectionInterval(int anchor, int lead)
Adds the specified interval to the current selection. Note that anchor can be less than, equal to, or greater than lead.

Parameters: anchor the index of the anchor item. lead the index of the lead item.

clearSelection

public void clearSelection()
Clears the current selection.

createSelectionModel

protected ListSelectionModel createSelectionModel()
Creates the default ListSelectionModel.

Returns: the ListSelectionModel

ensureIndexIsVisible

public void ensureIndexIsVisible(int i)
Scrolls this list to make the specified cell visible. This only works if the list is contained within a viewport.

Parameters: i The list index to make visible

See Also: JComponent

fireSelectionValueChanged

protected void fireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
Fire a {@link ListSelectionEvent} to all the registered ListSelectionListeners.

Parameters: firstIndex the lowest index covering the selection change. lastIndex the highest index covering the selection change. isAdjusting a flag indicating if this event is one in a series of events updating the selection.

getAccessibleContext

public AccessibleContext getAccessibleContext()

getAnchorSelectionIndex

public int getAnchorSelectionIndex()
Returns the index of the anchor item in the current selection, or -1 if there is no anchor item.

Returns: The item index.

getCellBounds

public Rectangle getCellBounds(int index0, int index1)
Returns the bounds of the rectangle that encloses both list cells with index0 and index1.

Parameters: index0 the index of the first cell index1 the index of the second cell

Returns: the bounds of the rectangle that encloses both list cells with index0 and index1, null if one of the indices is not valid

getCellRenderer

public ListCellRenderer getCellRenderer()
Gets the value of the {@link #cellRenderer} property.

Returns: The current value of the property

getDragEnabled

public boolean getDragEnabled()
Return the value of the dragEnabled property.

Returns: the value

Since: 1.4

getFirstVisibleIndex

public int getFirstVisibleIndex()
Returns the list index of the upper left or upper right corner of the visible rectangle of this list, depending on the {@link Component#getComponentOrientation} property.

Returns: The index of the first visible list cell, or -1 if none is visible.

getFixedCellHeight

public int getFixedCellHeight()
Gets the value of the {@link #fixedCellHeight} property. This property may be -1 to indicate that no cell height has been set. This property is also set implicitly when the {@link #prototypeCellValue} property is set.

Returns: The current value of the property

See Also: fixedCellHeight JList JList

getFixedCellWidth

public int getFixedCellWidth()
Gets the value of the {@link #fixedCellWidth} property. This property may be -1 to indicate that no cell width has been set. This property is also set implicitly when the {@link #prototypeCellValue} property is set.

Returns: The current value of the property

See Also: JList JList

getLastVisibleIndex

public int getLastVisibleIndex()
Returns the list index of the lower right or lower left corner of the visible rectangle of this list, depending on the {@link Component#getComponentOrientation} property.

Returns: The index of the last visible list cell, or -1 if none is visible.

getLayoutOrientation

public int getLayoutOrientation()
Returns the layout orientation, which will be one of {@link #VERTICAL}, {@link #VERTICAL_WRAP} and {@link #HORIZONTAL_WRAP}. The default value is {@link #VERTICAL}.

Returns: the orientation.

Since: 1.4

See Also: JList

getLeadSelectionIndex

public int getLeadSelectionIndex()
Returns the index of the lead item in the current selection, or -1 if there is no lead item.

Returns: The item index.

getListSelectionListeners

public ListSelectionListener[] getListSelectionListeners()
Returns an array of all ListSelectionListeners subscribed to this list.

Returns: The current subscribed listeners

Since: 1.4

getMaxSelectionIndex

public int getMaxSelectionIndex()
Returns the highest item index in the current selection, or -1 if there is no selection.

Returns: The index.

See Also: getMinSelectionIndex

getMinSelectionIndex

public int getMinSelectionIndex()
Returns the lowest item index in the current selection, or -1 if there is no selection.

Returns: The index.

See Also: getMaxSelectionIndex

getModel

public ListModel getModel()
Gets the value of the {@link #model} property.

Returns: The current value of the property

getNextMatch

public int getNextMatch(String prefix, int startIndex, Position.Bias direction)
Returns the index of the next list element (beginning at startIndex and moving in the specified direction through the list, looping around if necessary) that starts with prefix (ignoring case).

Parameters: prefix the prefix to search for in the cell values startIndex the index where to start searching from direction the search direction, either {@link Position.Bias#Forward} or {@link Position.Bias#Backward} (null is interpreted as {@link Position.Bias#Backward}.

Returns: the index of the found element or -1 if no such element has been found

Throws: IllegalArgumentException if prefix is null or startIndex is not valid

Since: 1.4

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Returns a size indicating how much space this list would like to consume, when contained in a scrollable viewport. This is part of the {@link Scrollable} interface, which interacts with {@link ScrollPaneLayout} and {@link JViewport} to define scrollable objects.

Returns: The preferred size

getPrototypeCellValue

public Object getPrototypeCellValue()
Returns the current value of the {@link #prototypeCellValue} property. This property holds a reference to a "prototype" data value -- typically a String -- which is used to calculate the {@link #fixedCellWidth} and {@link #fixedCellHeight} properties, using the {@link #cellRenderer} property to acquire a component to render the prototype.

Returns: The current prototype cell value

See Also: JList

getScrollableBlockIncrement

public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)

Return the number of pixels the list must scroll in order to move a "block" of the list into the provided visible rectangle. When the provided direction is positive, the call describes a "downwards" scroll, which will be exposing a cell at a greater index in the list than those elements currently showing. Then the provided direction is negative, the call describes an "upwards" scroll, which will be exposing a cell at a lesser index in the list than those elements currently showing.

If the provided orientation is HORIZONTAL, the above comments refer to "rightwards" for positive direction, and "leftwards" for negative.

Parameters: visibleRect The rectangle to scroll an element into orientation One of the numeric consants VERTICAL or HORIZONTAL direction An integer indicating the scroll direction: positive means forwards (down, right), negative means backwards (up, left)

Returns: The scrollable unit increment, in pixels

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Gets the value of the scrollableTracksViewportWidth property.

Returns: true if the viewport is larger (vertically) than the list and the list should be expanded to fit the viewport; false if the viewport is smaller than the list and the list should scroll (vertically) within the viewport

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Gets the value of the scrollableTracksViewportWidth property.

Returns: true if the viewport is larger (horizontally) than the list and the list should be expanded to fit the viewport; false if the viewport is smaller than the list and the list should scroll (horizontally) within the viewport

getScrollableUnitIncrement

public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)

Return the number of pixels the list must scroll in order to move a "unit" of the list into the provided visible rectangle. When the provided direction is positive, the call describes a "downwards" scroll, which will be exposing a cell at a greater index in the list than those elements currently showing. Then the provided direction is negative, the call describes an "upwards" scroll, which will be exposing a cell at a lesser index in the list than those elements currently showing.

If the provided orientation is HORIZONTAL, the above comments refer to "rightwards" for positive direction, and "leftwards" for negative.

Parameters: visibleRect The rectangle to scroll an element into orientation One of the numeric consants VERTICAL or HORIZONTAL direction An integer indicating the scroll direction: positive means forwards (down, right), negative means backwards (up, left)

Returns: The scrollable unit increment, in pixels

getSelectedIndex

public int getSelectedIndex()
Returns the minimum index of an element in the list which is currently selected.

Returns: A number in the half-open range [0, x) where x = getModel.getSize(), indicating the minimum index of an element in the list for which the element is selected, or -1 if no elements are selected

getSelectedIndices

public int[] getSelectedIndices()
Returns the indices of values in the {@link #model} property which are selected.

Returns: An array of model indices, each of which is selected according to the {@link #getSelectedValues} property

getSelectedValue

public Object getSelectedValue()
Returns the first value in the list's {@link #model} property which is selected, according to the list's {@link #selectionModel} property. This is equivalent to calling getModel()getElementAt(getSelectedIndex()), with a check for the special index value of -1 which returns null null.

Returns: The first selected element, or null if no element is selected.

See Also: JList

getSelectedValues

public Object[] getSelectedValues()
Returns all the values in the list's {@link #model} property which are selected, according to the list's {@link #selectionModel} property.

Returns: An array containing all the selected values

See Also: JList

getSelectionBackground

public Color getSelectionBackground()
Gets the value of the {@link #selectionBackground} property.

Returns: The current value of the property

getSelectionForeground

public Color getSelectionForeground()
Gets the value of the {@link #selectionForeground} property.

Returns: The current value of the property

getSelectionMode

public int getSelectionMode()
Returns the selection mode for the list (one of: {@link ListSelectionModel#SINGLE_SELECTION}, {@link ListSelectionModel#SINGLE_INTERVAL_SELECTION} and {@link ListSelectionModel#MULTIPLE_INTERVAL_SELECTION}).

Returns: The selection mode.

See Also: JList

getSelectionModel

public ListSelectionModel getSelectionModel()
Returns the selection model for the {@link JList} component. Note that this class contains a range of convenience methods for configuring the selection model:

Returns: The selection model.

getUI

public ListUI getUI()
Gets the value of the UI property.

Returns: The current property value

getUIClassID

public String getUIClassID()
Return the class identifier for the list's UI property. This should be the constant string "ListUI", and map to an appropriate UI class in the {@link UIManager}.

Returns: The class identifier

getValueIsAdjusting

public boolean getValueIsAdjusting()
Returns the valueIsAdjusting flag from the list's selection model.

Returns: the value

getVisibleRowCount

public int getVisibleRowCount()
Gets the value of the {@link #visibleRowCount} property. The default value is 8.

Returns: the current value of the property.

See Also: JList

indexToLocation

public Point indexToLocation(int index)
Returns location of the cell located at the specified index in the list.

Parameters: index of the cell for which location will be determined

Returns: location of the cell located at the specified index in the list.

isSelectedIndex

public boolean isSelectedIndex(int a)
Indicates whether the list element at a given index value is currently selected.

Parameters: a The index to check

Returns: true if a is the index of a selected list element

isSelectionEmpty

public boolean isSelectionEmpty()
Returns true if the model's selection is empty, otherwise false.

Returns: The return value of {@link ListSelectionModel#isSelectionEmpty}

locationToIndex

public int locationToIndex(Point location)
Returns index of the cell to which specified location is closest to. If the location is outside the bounds of the list, then the greatest index in the list model is returned. If the list model is empty, then -1 is returned.

Parameters: location for which to look for in the list

Returns: index of the cell to which specified location is closest to.

paramString

protected String paramString()
Returns a string describing the attributes for the JList component, for use in debugging. The return value is guaranteed to be non-null, but the format of the string may vary between implementations.

Returns: A string describing the attributes of the JList.

removeListSelectionListener

public void removeListSelectionListener(ListSelectionListener listener)
Removes a {@link ListSelectionListener} from the listener list for this list. The listener will no longer be called when the list's {@link #selectionModel} changes.

Parameters: listener The listener to remove

removeSelectionInterval

public void removeSelectionInterval(int index0, int index1)
Removes the specified interval from the current selection. Note that index0 can be less than, equal to, or greater than index1.

Parameters: index0 an index for one end of the range. index1 an index for the other end of the range.

setCellRenderer

public void setCellRenderer(ListCellRenderer renderer)
Sets the value of the {@link #getCellRenderer} property.

Parameters: renderer The new property value

setDragEnabled

public void setDragEnabled(boolean enabled)
Set the dragEnabled property.

Parameters: enabled new value

Since: 1.4

setFixedCellHeight

public void setFixedCellHeight(int h)
Sets the value of the {@link #fixedCellHeight} property. This property may be -1 to indicate that no cell height has been set. This property is also set implicitly when the {@link #prototypeCellValue} property is set, but setting it explicitly overrides the height computed from {@link #prototypeCellValue}.

Parameters: h the height.

See Also: JList JList

setFixedCellWidth

public void setFixedCellWidth(int w)
Sets the value of the {@link #fixedCellWidth} property. This property may be -1 to indicate that no cell width has been set. This property is also set implicitly when the {@link #prototypeCellValue} property is set, but setting it explicitly overrides the width computed from {@link #prototypeCellValue}.

Parameters: w the width.

See Also: JList JList

setLayoutOrientation

public void setLayoutOrientation(int orientation)
Sets the layout orientation (this is a bound property with the name 'layoutOrientation'). Valid orientations are {@link #VERTICAL}, {@link #VERTICAL_WRAP} and {@link #HORIZONTAL_WRAP}.

Parameters: orientation the orientation.

Throws: IllegalArgumentException if orientation is not one of the specified values.

Since: 1.4

See Also: getLayoutOrientation

setListData

public void setListData(Object[] listData)
Sets the {@link #model} property of the list to a new anonymous {@link AbstractListModel} subclass which accesses the provided Object array directly.

Parameters: listData The object array to build a new list model on

See Also: JList

setListData

public void setListData(Vector<?> listData)
Sets the {@link #model} property of the list to a new anonymous {@link AbstractListModel} subclass which accesses the provided vector directly.

Parameters: listData The object array to build a new list model on

See Also: JList

setModel

public void setModel(ListModel model)
Sets the value of the {@link #model} property. The list's {@link #listListener} is unsubscribed from the existing model, if it exists, and re-subscribed to the new model.

Parameters: model the new model (null not permitted).

Throws: IllegalArgumentException if model is null.

setPrototypeCellValue

public void setPrototypeCellValue(Object obj)

Set the {@link #prototypeCellValue} property. This property holds a reference to a "prototype" data value -- typically a String -- which is used to calculate the {@link #fixedCellWidth} and {@link #fixedCellHeight} properties, using the {@link #cellRenderer} property to acquire a component to render the prototype.

It is important that you not set this value to a component. It has to be a data value such as the objects you would find in the list's model. Setting it to a component will have undefined (and undesirable) affects.

Parameters: obj The new prototype cell value

See Also: JList

setSelectedIndex

public void setSelectedIndex(int a)
Adds the interval [a,a] to the set of selections managed by this list's {@link #selectionModel} property. Depending on the selection mode, this may cause existing selections to become invalid, or may simply expand the set of selections.

Parameters: a A number in the half-open range [0, x) where x = getModel.getSize(), indicating the index of an element in the list to select. When < 0 the selection is cleared.

See Also: JList selectionModel

setSelectedIndices

public void setSelectedIndices(int[] a)
For each element a[i] of the provided array a, calls {@link #setSelectedIndex} on a[i].

Parameters: a an array of selected indices (null not permitted).

Throws: NullPointerException if a is null.

See Also: JList selectionModel

setSelectedValue

public void setSelectedValue(Object obj, boolean scroll)
Sets the selection to cover only the specified value, if it exists in the model.

Parameters: obj The object to select scroll Whether to scroll the list to make the newly selected value visible

See Also: JList

setSelectionBackground

public void setSelectionBackground(Color c)
Sets the value of the {@link #selectionBackground} property.

Parameters: c The new value of the property

setSelectionForeground

public void setSelectionForeground(Color c)
Sets the value of the {@link #selectionForeground} property.

Parameters: c The new value of the property

setSelectionInterval

public void setSelectionInterval(int anchor, int lead)
Sets the current selection to the items in the specified range (inclusive). Note that anchor can be less than, equal to, or greater than lead.

Parameters: anchor the index of the anchor item. lead the index of the anchor item.

setSelectionMode

public void setSelectionMode(int a)
Sets the list's "selectionMode" property, which simply mirrors the same property on the list's {@link #selectionModel} property. This property should be one of the integer constants SINGLE_SELECTION, SINGLE_INTERVAL_SELECTION, or MULTIPLE_INTERVAL_SELECTION from the {@link ListSelectionModel} interface.

Parameters: a The new selection mode

setSelectionModel

public void setSelectionModel(ListSelectionModel model)
Sets the value of the {@link #selectionModel} property. The list's {@link #listListener} is unsubscribed from the existing selection model, if it exists, and re-subscribed to the new selection model.

Parameters: model The new property value

setUI

public void setUI(ListUI ui)
Sets the value of the UI property.

Parameters: ui The new property value

setValueIsAdjusting

public void setValueIsAdjusting(boolean isAdjusting)
Sets the valueIsAdjusting flag in the list's selection model.

Parameters: isAdjusting the new value

setVisibleRowCount

public void setVisibleRowCount(int vc)
Sets the value of the {@link #visibleRowCount} property.

Parameters: vc The new property value

See Also: getVisibleRowCount

updateUI

public void updateUI()
Calls {@link #setUI} with the {@link ListUI} subclass returned from calling {@link UIManager#getUI}.