javax.swing
Class JList

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JList
All Implemented Interfaces:
Accessible, java.awt.image.ImageObserver, MenuContainer, Scrollable, Serializable

public class JList
extends JComponent
implements Scrollable, Accessible

Safe:

See Also:
Serialized Form

Field Summary
private  ListCellRenderer cellRenderer
           
private  ListModel dataModel
           
private  boolean dragEnabled
           
private  int fixedCellHeight
           
private  int fixedCellWidth
           
static int HORIZONTAL_WRAP
          Enabled: Indicates "newspaper style" with the cells flowing horizontally then vertically.
private  int horizontalScrollIncrement
           
private  int layoutOrientation
          How to layout the cells, defaults to VERTICAL.
private  Object prototypeCellValue
           
private  Color selectionBackground
           
private  Color selectionForeground
           
private  ListSelectionListener selectionListener
           
private  ListSelectionModel selectionModel
           
private static String uiClassID
           
static int VERTICAL
          Enabled: Indicates the default layout: one column of cells.
static int VERTICAL_WRAP
          Enabled: Indicates "newspaper style" layout with the cells flowing vertically then horizontally.
private  int visibleRowCount
           
 
Fields inherited from class javax.swing.JComponent
_bounds, accessibleContext, listenerList, paintingChild, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
JList()
          Enabled: Constructs a JList with an empty model.
JList(ListModel dataModel)
          Enabled: Constructs a JList that displays the elements in the specified, non-null model.
JList(Object[] listData)
          Enabled: Constructs a JList that displays the elements in the specified array.
JList(Vector listData)
          Enabled: Constructs a JList that displays the elements in the specified Vector.
 
Method Summary
 void addListSelectionListener(ListSelectionListener listener)
          Enabled: Adds a listener to the list that's notified each time a change to the selection occurs.
 void addSelectionInterval(int anchor, int lead)
          Enabled: Sets the selection to be the union of the specified interval with current selection.
private  void checkScrollableParameters(Rectangle visibleRect, int orientation)
          --- The Scrollable Implementation ---
 void clearSelection()
          Enabled: Clears the selection - after calling this method isSelectionEmpty will return true.
protected  ListSelectionModel createSelectionModel()
          Returns an instance of DefaultListSelectionModel.
 void ensureIndexIsVisible(int index)
          Enabled: Scrolls the viewport to make the specified cell completely visible.
protected  void fireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
          Notifies JList ListSelectionListeners that the selection model has changed.
 AccessibleContext getAccessibleContext()
          Suppressed: Gets the AccessibleContext associated with this JList.
 int getAnchorSelectionIndex()
          Enabled: Returns the first index argument from the most recent addSelectionModel or setSelectionInterval call.
 Rectangle getCellBounds(int index0, int index1)
          Enabled: Returns the bounds of the specified range of items in JList coordinates.
 ListCellRenderer getCellRenderer()
          Enabled: Returns the object that renders the list items.
 boolean getDragEnabled()
          Enabled: Gets the dragEnabled property.
 int getFirstVisibleIndex()
          Enabled: Returns the index of the first visible cell.
 int getFixedCellHeight()
          Enabled: Returns the fixed cell height value -- the value specified by setting the fixedCellHeight property, rather than that calculated from the list elements.
 int getFixedCellWidth()
          Enabled: Returns the fixed cell width value -- the value specified by setting the fixedCellWidth property, rather than that calculated from the list elements.
 int getLastVisibleIndex()
          Enabled: Returns the index of the last visible cell.
 int getLayoutOrientation()
          Enabled: Returns JList.VERTICAL if the layout is a single column of cells, or JList.VERTICAL_WRAP if the layout is "newspaper style" with the content flowing vertically then horizontally or JList.HORIZONTAL_WRAP if the layout is "newspaper style" with the content flowing horizontally then vertically.
 int getLeadSelectionIndex()
          Enabled: Returns the second index argument from the most recent addSelectionInterval or setSelectionInterval call.
 ListSelectionListener[] getListSelectionListeners()
          Suppressed: Returns an array of all the ListSelectionListeners added to this JList with addListSelectionListener().
 int getMaxSelectionIndex()
          Enabled: Returns the largest selected cell index.
 int getMinSelectionIndex()
          Enabled: Returns the smallest selected cell index.
 ListModel getModel()
          Enabled: Returns the data model that holds the list of items displayed by the JList component.
 int getNextMatch(String prefix, int startIndex, javax.swing.text.Position.Bias bias)
          Suppressed: Returns the next list element that starts with a prefix.
 Dimension getPreferredScrollableViewportSize()
          Enabled: Computes the size of the viewport needed to display visibleRowCount rows.
 Object getPrototypeCellValue()
          Enabled: Returns the cell width of the "prototypical cell" -- a cell used for the calculation of cell widths, because it has the same value as all other list items.
 int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
          Enabled: Returns the distance to scroll to expose the next or previous block.
 boolean getScrollableTracksViewportHeight()
          Enabled: Returns true if this JList is displayed in a JViewport and the viewport is taller than JList's preferred height, or if the layout orientation is VERTICAL_WRAP and the number of visible rows is <= 0; otherwise returns false.
 boolean getScrollableTracksViewportWidth()
          Enabled: Returns true if this JList is displayed in a JViewport and the viewport is wider than JList's preferred width; or if the layout orientation is HORIZONTAL_WRAP and the visible row count is <= 0; otherwise returns false.
 int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
          Enabled: Returns the distance to scroll to expose the next or previous row (for vertical scrolling) or character (for horizontal scrolling).
 int getSelectedIndex()
          Enabled: Returns the first selected index; returns -1 if there is no selected item.
 int[] getSelectedIndices()
          Enabled: Returns an array of all of the selected indices in increasing order.
 Object getSelectedValue()
          Enabled: Returns the first selected value, or null if the selection is empty.
 Object[] getSelectedValues()
          Enabled: Returns an array of the values for the selected cells.
 Color getSelectionBackground()
          Enabled: Returns the background color for selected cells.
 Color getSelectionForeground()
          Enabled: Returns the selection foreground color.
 int getSelectionMode()
          Enabled: Returns whether single-item or multiple-item selections are allowed.
 ListSelectionModel getSelectionModel()
          Enabled: Returns the value of the current selection model.
 String getToolTipText(MouseEvent event)
          Enabled: Overrides JComponent's getToolTipText method in order to allow the renderer's tips to be used if it has text set.
 javax.swing.plaf.ListUI getUI()
          Suppressed: Returns the look and feel (L&F) object that renders this component.
 String getUIClassID()
          Suppressed: Returns the suffix used to construct the name of the look and feel (L&F) class used to render this component.
 boolean getValueIsAdjusting()
          Enabled: Returns the value of the data model's isAdjusting property.
 int getVisibleRowCount()
          Enabled: Returns the preferred number of visible rows.
 Point indexToLocation(int index)
          Enabled: Returns the origin of the specified item in JList coordinates.
 boolean isSelectedIndex(int index)
          Enabled: Returns true if the specified index is selected.
 boolean isSelectionEmpty()
          Enabled: Returns true if nothing is selected.
 int locationToIndex(Point location)
          Enabled: Convert a point in JList coordinates to the closest index of the cell at that location.
protected  String paramString()
          Returns a string representation of this JList.
 void removeListSelectionListener(ListSelectionListener listener)
          Enabled: Removes a listener from the list that's notified each time a change to the selection occurs.
 void removeSelectionInterval(int index0, int index1)
          Enabled: Sets the selection to be the set difference of the specified interval and the current selection.
 void setCellRenderer(ListCellRenderer cellRenderer)
          Enabled: Sets the delegate that's used to paint each cell in the list.
 void setDragEnabled(boolean b)
          Enabled: Sets the dragEnabled property, which must be true to enable automatic drag handling (the first part of drag and drop) on this component.
 void setFixedCellHeight(int height)
          Enabled: Sets the height of every cell in the list.
 void setFixedCellWidth(int width)
          Enabled: Sets the width of every cell in the list.
 void setLayoutOrientation(int layoutOrientation)
          Enabled: Defines the way list cells are layed out.
 void setListData(Object[] listData)
          Enabled: Constructs a ListModel from an array of objects and then applies setModel to it.
 void setListData(Vector listData)
          Enabled: Constructs a ListModel from a Vector and then applies setModel to it.
 void setModel(ListModel model)
          Enabled: Sets the model that represents the contents or "value" of the list and clears the list selection after notifying PropertyChangeListeners.
 void setPrototypeCellValue(Object prototypeCellValue)
          Enabled: Computes the fixedCellWidth and fixedCellHeight properties by configuring the cellRenderer to index equals zero for the specified value and then computing the renderer component's preferred size.
 void setSelectedIndex(int index)
          Enabled: Selects a single cell.
 void setSelectedIndices(int[] indices)
          Enabled: Selects a set of cells.
 void setSelectedValue(Object anObject, boolean shouldScroll)
          Enabled: Selects the specified object from the list.
 void setSelectionBackground(Color selectionBackground)
          Enabled: Sets the background color for selected cells.
 void setSelectionForeground(Color selectionForeground)
          Enabled: Sets the foreground color for selected cells.
 void setSelectionInterval(int anchor, int lead)
          Enabled: Selects the specified interval.
 void setSelectionMode(int selectionMode)
          Enabled: Determines whether single-item or multiple-item selections are allowed.
 void setSelectionModel(ListSelectionModel selectionModel)
          Enabled: Sets the selectionModel for the list to a non-null ListSelectionModel implementation.
 void setUI(javax.swing.plaf.ListUI ui)
          Suppressed: Sets the look and feel (L&F) object that renders this component.
 void setValueIsAdjusting(boolean b)
          Enabled: Sets the data model's isAdjusting property to true, so that a single event will be generated when all of the selection events have finished (for example, when the mouse is being dragged over the list in selection mode).
 void setVisibleRowCount(int visibleRowCount)
          Enabled: Sets the preferred number of rows in the list that can be displayed without a scrollbar, as determined by the nearest JViewport ancestor, if any.
private  void updateFixedCellSize()
           
 void updateUI()
          Suppressed: Resets the UI property with the value from the current look and feel.
private  void writeObject(ObjectOutputStream s)
          Before writing a JComponent to an ObjectOutputStream we temporarily uninstall its UI.
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, alwaysOnTop, checkIfChildObscuredBySibling, componentInputMapChanged, computeVisibleRect, computeVisibleRect, compWriteObjectNotify, contains, createToolTip, disable, enable, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getManagingFocusBackwardTraversalKeys, getManagingFocusForwardTraversalKeys, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getWriteObjCounter, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseMotionEvent, putClientProperty, rectangleIsObscured, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, setWriteObjCounter, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, get, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, iterate, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, size, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, toString, transferFocus, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

uiClassID

private static final String uiClassID
See Also:
getUIClassID(), JComponent.readObject(java.io.ObjectInputStream)

VERTICAL

public static final int VERTICAL
Enabled: Indicates the default layout: one column of cells.

Since:
1.4
See Also:
setLayoutOrientation(int)

VERTICAL_WRAP

public static final int VERTICAL_WRAP
Enabled: Indicates "newspaper style" layout with the cells flowing vertically then horizontally.

Since:
1.4
See Also:
setLayoutOrientation(int)

HORIZONTAL_WRAP

public static final int HORIZONTAL_WRAP
Enabled: Indicates "newspaper style" with the cells flowing horizontally then vertically.

Since:
1.4
See Also:
setLayoutOrientation(int)

fixedCellWidth

private int fixedCellWidth

fixedCellHeight

private int fixedCellHeight

horizontalScrollIncrement

private int horizontalScrollIncrement

prototypeCellValue

private Object prototypeCellValue

visibleRowCount

private int visibleRowCount

selectionForeground

private Color selectionForeground

selectionBackground

private Color selectionBackground

dragEnabled

private boolean dragEnabled

selectionModel

private ListSelectionModel selectionModel

dataModel

private ListModel dataModel

cellRenderer

private ListCellRenderer cellRenderer

selectionListener

private ListSelectionListener selectionListener

layoutOrientation

private int layoutOrientation
How to layout the cells, defaults to VERTICAL.

Constructor Detail

JList

public JList(ListModel dataModel)
Enabled: Constructs a JList that displays the elements in the specified, non-null model. All JList constructors delegate to this one.

Parameters:
dataModel - the data model for this list

JList

public JList(Object[] listData)
Enabled: Constructs a JList that displays the elements in the specified array. This constructor just delegates to the ListModel constructor.

Parameters:
listData - the array of Objects to be loaded into the data model

JList

public JList(Vector listData)
Enabled: Constructs a JList that displays the elements in the specified Vector. This constructor just delegates to the ListModel constructor.

Parameters:
listData - the Vector to be loaded into the data model

JList

public JList()
Enabled: Constructs a JList with an empty model.

Method Detail

getUI

public javax.swing.plaf.ListUI getUI()
Suppressed: Returns the look and feel (L&F) object that renders this component.

Returns:
the ListUI object that renders this component

setUI

public void setUI(javax.swing.plaf.ListUI ui)
Suppressed: Sets the look and feel (L&F) object that renders this component.

Parameters:
ui - the ListUI L&F object
See Also:
UIDefaults.getUI(javax.swing.JComponent)

updateUI

public void updateUI()
Suppressed: Resets the UI property with the value from the current look and feel.

Overrides:
updateUI in class JComponent
See Also:
UIManager.getUI(javax.swing.JComponent)

getUIClassID

public String getUIClassID()
Suppressed: Returns the suffix used to construct the name of the look and feel (L&F) class used to render this component.

Overrides:
getUIClassID in class JComponent
Returns:
the string "ListUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

updateFixedCellSize

private void updateFixedCellSize()

getPrototypeCellValue

public Object getPrototypeCellValue()
Enabled: Returns the cell width of the "prototypical cell" -- a cell used for the calculation of cell widths, because it has the same value as all other list items.

Returns:
the value of the prototypeCellValue property
See Also:
setPrototypeCellValue(java.lang.Object)

setPrototypeCellValue

public void setPrototypeCellValue(Object prototypeCellValue)
Enabled: Computes the fixedCellWidth and fixedCellHeight properties by configuring the cellRenderer to index equals zero for the specified value and then computing the renderer component's preferred size. These properties are useful when the list is too long to allow JList to compute the width/height of each cell and there is a single cell value that is known to occupy as much space as any of the others.

Note that we do set the fixedCellWidth and fixedCellHeight properties here but only a prototypeCellValue PropertyChangeEvent is fired.

To see an example which sets this property, see the class description above.

The default value of this property is null.

This is a JavaBeans bound property.

Parameters:
prototypeCellValue - the value on which to base fixedCellWidth and fixedCellHeight
See Also:
getPrototypeCellValue(), setFixedCellWidth(int), setFixedCellHeight(int), JComponent.addPropertyChangeListener(java.beans.PropertyChangeListener)

getFixedCellWidth

public int getFixedCellWidth()
Enabled: Returns the fixed cell width value -- the value specified by setting the fixedCellWidth property, rather than that calculated from the list elements.

Returns:
the fixed cell width
See Also:
setFixedCellWidth(int)

setFixedCellWidth

public void setFixedCellWidth(int width)
Enabled: Sets the width of every cell in the list. If width is -1, cell widths are computed by applying getPreferredSize to the cellRenderer component for each list element.

The default value of this property is -1.

This is a JavaBeans bound property.

Parameters:
width - the width, in pixels, for all cells in this list
See Also:
getPrototypeCellValue(), setFixedCellWidth(int), JComponent.addPropertyChangeListener(java.beans.PropertyChangeListener)

getFixedCellHeight

public int getFixedCellHeight()
Enabled: Returns the fixed cell height value -- the value specified by setting the fixedCellHeight property, rather than that calculated from the list elements.

Returns:
the fixed cell height, in pixels
See Also:
setFixedCellHeight(int)

setFixedCellHeight

public void setFixedCellHeight(int height)
Enabled: Sets the height of every cell in the list. If height is -1, cell heights are computed by applying getPreferredSize to the cellRenderer component for each list element.

The default value of this property is -1.

This is a JavaBeans bound property.

Parameters:
height - an integer giving the height, in pixels, for all cells in this list
See Also:
getPrototypeCellValue(), setFixedCellWidth(int), JComponent.addPropertyChangeListener(java.beans.PropertyChangeListener)

getCellRenderer

public ListCellRenderer getCellRenderer()
Enabled: Returns the object that renders the list items.

Returns:
the ListCellRenderer
See Also:
setCellRenderer(javax.swing.ListCellRenderer)

setCellRenderer

public void setCellRenderer(ListCellRenderer cellRenderer)
Enabled: Sets the delegate that's used to paint each cell in the list. If prototypeCellValue was set then the fixedCellWidth and fixedCellHeight properties are set as well. Only one PropertyChangeEvent is generated however - for the cellRenderer property.

The default value of this property is provided by the ListUI delegate, i.e. by the look and feel implementation.

To see an example which sets the cell renderer, see the class description above.

This is a JavaBeans bound property.

Parameters:
cellRenderer - the ListCellRenderer that paints list cells
See Also:
getCellRenderer()

getSelectionForeground

public Color getSelectionForeground()
Enabled: Returns the selection foreground color.

Returns:
the Color object for the foreground property
See Also:
setSelectionForeground(java.awt.Color), setSelectionBackground(java.awt.Color)

setSelectionForeground

public void setSelectionForeground(Color selectionForeground)
Enabled: Sets the foreground color for selected cells. Cell renderers can use this color to render text and graphics for selected cells.

The default value of this property is defined by the look and feel implementation.

This is a JavaBeans bound property.

Parameters:
selectionForeground - the Color to use in the foreground for selected list items
See Also:
getSelectionForeground(), setSelectionBackground(java.awt.Color), JComponent.setForeground(java.awt.Color), JComponent.setBackground(java.awt.Color), JComponent.setFont(java.awt.Font)

getSelectionBackground

public Color getSelectionBackground()
Enabled: Returns the background color for selected cells.

Returns:
the Color used for the background of selected list items
See Also:
setSelectionBackground(java.awt.Color), setSelectionForeground(java.awt.Color)

setSelectionBackground

public void setSelectionBackground(Color selectionBackground)
Enabled: Sets the background color for selected cells. Cell renderers can use this color to the fill selected cells.

The default value of this property is defined by the look and feel implementation.

This is a JavaBeans bound property.

Parameters:
selectionBackground - the Color to use for the background of selected cells
See Also:
getSelectionBackground(), setSelectionForeground(java.awt.Color), JComponent.setForeground(java.awt.Color), JComponent.setBackground(java.awt.Color), JComponent.setFont(java.awt.Font)

getVisibleRowCount

public int getVisibleRowCount()
Enabled: Returns the preferred number of visible rows.

Returns:
an integer indicating the preferred number of rows to display without using a scroll bar
See Also:
setVisibleRowCount(int)

setVisibleRowCount

public void setVisibleRowCount(int visibleRowCount)
Enabled: Sets the preferred number of rows in the list that can be displayed without a scrollbar, as determined by the nearest JViewport ancestor, if any. The value of this property only affects the value of the JList's preferredScrollableViewportSize.

The default value of this property is 8.

This is a JavaBeans bound property.

Parameters:
visibleRowCount - an integer specifying the preferred number of visible rows
See Also:
getVisibleRowCount(), JComponent.getVisibleRect(), JViewport

getLayoutOrientation

public int getLayoutOrientation()
Enabled: Returns JList.VERTICAL if the layout is a single column of cells, or JList.VERTICAL_WRAP if the layout is "newspaper style" with the content flowing vertically then horizontally or JList.HORIZONTAL_WRAP if the layout is "newspaper style" with the content flowing horizontally then vertically.

Returns:
the value of the layoutOrientation property
Since:
1.4
See Also:
setLayoutOrientation(int)

setLayoutOrientation

public void setLayoutOrientation(int layoutOrientation)
Enabled: Defines the way list cells are layed out. Consider a JList with four cells, this can be layed out in one of the following ways:
   0
   1
   2
   3
 
   0  1
   2  3
 
   0  2
   1  3
 

These correspond to the following values:
JList.VERTICAL The cells should be layed out vertically in one column.
JList.HORIZONTAL_WRAP The cells should be layed out horizontally, wrapping to a new row as necessary. The number of rows to use will either be defined by getVisibleRowCount if > 0, otherwise the number of rows will be determined by the width of the JList.
JList.VERTICAL_WRAP The cells should be layed out vertically, wrapping to a new column as necessary. The number of rows to use will either be defined by getVisibleRowCount if > 0, otherwise the number of rows will be determined by the height of the JList.
The default value of this property is JList.VERTICAL.

This will throw an IllegalArgumentException if layoutOrientation is not one of JList.HORIZONTAL_WRAP or JList.VERTICAL or JList.VERTICAL_WRAP

Parameters:
layoutOrientation - New orientation, one of JList.HORIZONTAL_WRAP, JList.VERTICAL or JList.VERTICAL_WRAP.
Since:
1.4
See Also:
getLayoutOrientation(), setVisibleRowCount(int), getScrollableTracksViewportHeight()

getFirstVisibleIndex

public int getFirstVisibleIndex()
Enabled: Returns the index of the first visible cell. The cell considered to be "first" depends on the list's componentOrientation property. If the orientation is horizontal left-to-right, then the first visible cell is in the list's upper-left corner. If the orientation is horizontal right-to-left, then the first visible cell is in the list's upper-right corner. If nothing is visible or the list is empty, a -1 is returned. Note that the returned cell may only be partially visible.

Returns:
the index of the first visible cell
See Also:
getLastVisibleIndex(), JComponent.getVisibleRect()

getLastVisibleIndex

public int getLastVisibleIndex()
Enabled: Returns the index of the last visible cell. The cell considered to be "last" depends on the list's componentOrientation property. If the orientation is horizontal left-to-right, then the last visible cell is in the JList's lower-right corner. If the orientation is horizontal right-to-left, then the last visible cell is in the JList's lower-left corner. If nothing is visible or the list is empty, a -1 is returned. Note that the returned cell may only be partially visible.

Returns:
the index of the last visible cell
See Also:
getFirstVisibleIndex(), JComponent.getVisibleRect()

ensureIndexIsVisible

public void ensureIndexIsVisible(int index)
Enabled: Scrolls the viewport to make the specified cell completely visible. Note, for this method to work, the JList must be displayed within a JViewport.

Parameters:
index - the index of the cell to make visible
See Also:
JComponent.scrollRectToVisible(java.awt.Rectangle), JComponent.getVisibleRect()

setDragEnabled

public void setDragEnabled(boolean b)
Enabled: Sets the dragEnabled property, which must be true to enable automatic drag handling (the first part of drag and drop) on this component. The transferHandler property needs to be set to a non-null value for the drag to do anything. The default value of the dragEnabled property is false.

When automatic drag handling is enabled, most look and feels begin a drag-and-drop operation whenever the user presses the mouse button over a selection and then moves the mouse a few pixels. Setting this property to true can therefore have a subtle effect on how selections behave.

Some look and feels might not support automatic drag and drop; they will ignore this property. You can work around such look and feels by modifying the component to directly call the exportAsDrag method of a TransferHandler.

Parameters:
b - the value to set the dragEnabled property to
Since:
1.4
See Also:
java.awt.GraphicsEnvironment#isHeadless, getDragEnabled(), JComponent.setTransferHandler(javax.swing.TransferHandler), TransferHandler

getDragEnabled

public boolean getDragEnabled()
Enabled: Gets the dragEnabled property.

Returns:
the value of the dragEnabled property
Since:
1.4
See Also:
setDragEnabled(boolean)

getNextMatch

public int getNextMatch(String prefix,
                        int startIndex,
                        javax.swing.text.Position.Bias bias)
Suppressed: Returns the next list element that starts with a prefix.

Parameters:
prefix - the string to test for a match
startIndex - the index for starting the search
bias - the search direction, either Position.Bias.Forward or Position.Bias.Backward.
Returns:
the index of the next list element that starts with the prefix; otherwise -1
Since:
1.4

getToolTipText

public String getToolTipText(MouseEvent event)
Enabled: Overrides JComponent's getToolTipText method in order to allow the renderer's tips to be used if it has text set.

Note: For JList to properly display tooltips of its renderers JList must be a registered component with the ToolTipManager. This is done automatically in the constructor, but if at a later point JList is told setToolTipText(null) it will unregister the list component, and no tips from renderers will display anymore.

Overrides:
getToolTipText in class JComponent
See Also:
JComponent.getToolTipText()

locationToIndex

public int locationToIndex(Point location)
Enabled: Convert a point in JList coordinates to the closest index of the cell at that location. To determine if the cell actually contains the specified location use a combination of this method and getCellBounds. Returns -1 if the model is empty.

Parameters:
location - the coordinates of the cell, relative to JList
Returns:
an integer -- the index of the cell at the given location, or -1.