This class is a facade over three separate objects:
ListModel
,
ListSelectionModel
and
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
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 in | Bound? |
accessibleContext | list | no |
anchorSelectionIndex | selection | no |
cellRenderer | list | yes |
dragEnabled | list | no |
firstVisibleIndex | list | no |
fixedCellHeight | list | yes |
fixedCellWidth | list | yes |
lastVisibleIndex | list | no |
layoutOrientation | list | yes |
leadSelectionIndex | selection | no |
maxSelectionIndex | selection | no |
minSelectionIndex | selection | no |
model | list | yes |
opaque | list | no |
preferredScrollableViewportSize | list | no |
prototypeCellValue | list | yes |
scrollableTracksViewportHeight | list | no |
scrollableTracksViewportWidth | list | no |
selectedIndex | selection | no |
selectedIndices | selection | no |
selectedValue | model | no |
selectedValues | model | no |
selectionBackground | list | yes |
selectionEmpty | selection | no |
selectionForeground | list | yes |
selectionMode | selection | no |
selectionModel | list | yes |
UI | list | yes |
UIClassID | list | no |
valueIsAdjusting | list | no |
visibleRowCount | list | no |
getAccessibleContext
public AccessibleContext getAccessibleContext()
If a component supports the Accessibility API then this method should
not return null
. Only classes which must extend an accessible
class, but must not itself be accessible, may return null.
- getAccessibleContext in interface Accessible
- getAccessibleContext in interface JComponent
- the context associated with this accessible object
getCellBounds
public Rectangle getCellBounds(int index0,
int index1)
Returns the bounds of the rectangle that encloses both list cells
with index0 and index1.
index0
- the index of the first cellindex1
- the index of the second cell
- the bounds of the rectangle that encloses both list cells
with index0 and index1,
null
if one of the indices is
not valid
getDragEnabled
public boolean getDragEnabled()
Return the value of the dragEnabled
property.
- the value
- 1.4
getFirstVisibleIndex
public int getFirstVisibleIndex()
Returns the list index of the upper left or upper right corner of the
JList
property, depending on the JList
property.
- The index of the first visible list cell, or
-1
if none is visible.
getLastVisibleIndex
public int getLastVisibleIndex()
Returns the list index of the lower right or lower left corner of the
JList
property, depending on the JList
property.
- The index of the first visible list cell, or
-1
if none is visible.
getLayoutOrientation
public int getLayoutOrientation()
Returns the layout orientation.
- the orientation, one of
JList.VERTICAL
,
JList.VERTICAL_WRAP
and JList.HORIZONTAL_WRAP
- 1.4
getModel
public ListModel getModel()
Gets the value of the JList
property.
- The current value of the property
getNextMatch
public int getNextMatch(String prefix,
int startIndex,
Position.Bias bias)
Returns the next list element (beginning from startIndex
that starts with prefix
. Searching is done in the direction
specified by bias
.
prefix
- the prefix to search for in the cell valuesstartIndex
- the index where to start searching frombias
- the search direction, either Position.Bias.Forward
or Position.Bias.Backward
- the index of the found element or -1 if no such element has
been found
IllegalArgumentException
- if prefix is null
or
startIndex is not valid
- 1.4
getPrototypeCellValue
public Object getPrototypeCellValue()
Returns the current value of the JList
property. This property holds a reference to a "prototype" data value
-- typically a String -- which is used to calculate the JList
and JList
properties, using the
JList
property to acquire a component to render the
prototype.
- The current prototype cell value
setPrototypeCellValue(Object)
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.
- getScrollableBlockIncrement in interface Scrollable
visibleRect
- The rectangle to scroll an element intoorientation
- 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)
- The scrollable unit increment, in pixels
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()
Gets the value of the JList
property.
- getScrollableTracksViewportHeight in interface Scrollable
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 JList
property.
- getScrollableTracksViewportWidth in interface Scrollable
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.
- getScrollableUnitIncrement in interface Scrollable
visibleRect
- The rectangle to scroll an element intoorientation
- 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)
- The scrollable unit increment, in pixels
getSelectedIndex
public int getSelectedIndex()
Returns the minimum index of an element in the list which is currently
selected.
- 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 JList
property which are
selected.
- An array of model indices, each of which is selected according
to the
JList
property
getSelectedValue
public Object getSelectedValue()
Returns the first value in the list's JList
property which is
selected, according to the list's JList
property.
This is equivalent to calling
getModel()getElementAt(getSelectedIndex())
, with a check
for the special index value of -1
which returns null
null
.
- The first selected element, or
null
if no element
is selected.
getSelectedValues
getSelectedValues
public Object[] getSelectedValues()
Returns all the values in the list's JList
property which
are selected, according to the list's JList
property.
- An array containing all the selected values
getSelectedValue
getUI
public ListUI getUI()
Gets the value of the UI property.
- 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
UIManager
.
- getUIClassID in interface JComponent
- The class identifier
getValueIsAdjusting
public boolean getValueIsAdjusting()
Returns the value of the valueIsAdjusting
property.
- the value
getVisibleRowCount
public int getVisibleRowCount()
Gets the value of the JList
property.
- the current value of the property.
indexToLocation
public Point indexToLocation(int index)
Returns location of the cell located at the specified index in the list.
index
- of the cell for which location will be determined
- 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.
a
- The index to check
true
if a
is the index of a selected
list element
locationToIndex
public int locationToIndex(Point location)
Returns index of the cell to which specified location is closest to
location
- for which to look for in the list
- index of the cell to which specified location is closest to.
setDragEnabled
public void setDragEnabled(boolean enabled)
Set the dragEnabled
property.
enabled
- new value
- 1.4
setFixedCellHeight
public void setFixedCellHeight(int h)
Sets the value of the JList
property. This property
may be -1
to indicate that no cell height has been
set. This property is also set implicitly when the JList
property is set, but setting it explicitly
overrides the height computed from JList
.
getFixedCellHeight()
, getPrototypeCellValue()
setFixedCellWidth
public void setFixedCellWidth(int w)
Sets the value of the JList
property. This property
may be -1
to indicate that no cell width has been
set. This property is also set implicitly when the JList
property is set, but setting it explicitly
overrides the width computed from JList
.
getFixedCellHeight()
, getPrototypeCellValue()
setLayoutOrientation
public void setLayoutOrientation(int orientation)
Sets the layout orientation.
orientation
- the orientation to set, one of JList.VERTICAL
,
JList.VERTICAL_WRAP
and JList.HORIZONTAL_WRAP
- 1.4
setModel
public void setModel(ListModel model)
Sets the value of the JList
property. The list's JList
is unsubscribed from the existing model, if it exists,
and re-subscribed to the new model.
model
- The new property value
setPrototypeCellValue
public void setPrototypeCellValue(Object obj)
Set the
JList
property. This property holds a
reference to a "prototype" data value -- typically a String -- which
is used to calculate the
JList
and
JList
properties, using the
JList
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.
obj
- The new prototype cell value
getPrototypeCellValue()
setSelectedIndex
public void setSelectedIndex(int a)
Adds the interval [a,a]
to the set of selections managed
by this list's JList
property. Depending on the
selection mode, this may cause existing selections to become invalid,
or may simply expand the set of selections.
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.
setSelectionMode(int)
, JList
setSelectedValue
public void setSelectedValue(Object obj,
boolean scroll)
Sets the selection to cover only the specified value, if it
exists in the model.
obj
- The object to selectscroll
- Whether to scroll the list to make the newly selected
value visible
ensureIndexIsVisible(int)
setSelectionBackground
public void setSelectionBackground(Color c)
Sets the value of the JList
property.
c
- The new value of the property
setSelectionForeground
public void setSelectionForeground(Color c)
Sets the value of the JList
property.
c
- The new value of the property
setSelectionMode
public void setSelectionMode(int a)
Sets the list's "selectionMode" property, which simply mirrors the
same property on the list's
JList
property. This
property should be one of the integer constants
SINGLE_SELECTION
,
SINGLE_INTERVAL_SELECTION
,
or
MULTIPLE_INTERVAL_SELECTION
from the
ListSelectionModel
interface.
a
- The new selection mode
setSelectionModel
public void setSelectionModel(ListSelectionModel model)
Sets the value of the JList
property. The list's
JList
is unsubscribed from the existing selection
model, if it exists, and re-subscribed to the new selection model.
model
- The new property value
setUI
public void setUI(ListUI ui)
Sets the value of the UI property.
ui
- The new property value
setValueIsAdjusting
public void setValueIsAdjusting(boolean isAdjusting)
Sets the valueIsAdjusting
property.
isAdjusting
- the new value
setVisibleRowCount
public void setVisibleRowCount(int vc)
Sets the value of the JList
property.
JList.java --
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.