This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.swing.plaf.basic
class BasicListUI

java.lang.Object extended by javax.swing.plaf.ComponentUI extended by javax.swing.plaf.ListUI extended by javax.swing.plaf.basic.BasicListUI

public class BasicListUI
extends ListUI

An extensible implementation of {@code ListUI}.

{@code BasicListUI} instances cannot be shared between multiple lists.


Nested Class Summary
 class

           This inner class is marked "public" due to a compiler bug.
 class

           The ListDataListener that's added to the JLists model at installUI time, and whenever the JList.model property changes.
 class

           The ListSelectionListener that's added to the JLists selection model at installUI time, and whenever the JList.selectionModel property changes.
 class

           Mouse input, and focus handling for JList.
 class

           The PropertyChangeListener that's added to the JList at installUI time.
 
Field Summary
protected int cellHeight
          
protected int[] cellHeights
          
protected static int cellRendererChanged
          
protected int cellWidth
          
protected static int fixedCellHeightChanged
          
protected static int fixedCellWidthChanged
          
protected FocusListener focusListener
          
protected static int fontChanged
          
protected JList list
          
protected ListDataListener listDataListener
          
protected ListSelectionListener listSelectionListener
          
protected static int modelChanged
          
protected MouseInputListener mouseInputListener
          
protected PropertyChangeListener propertyChangeListener
          
protected static int prototypeCellValueChanged
          
protected CellRendererPane rendererPane
          
protected static int selectionModelChanged
          
protected int updateLayoutStateNeeded
          
 
Constructor Summary

          
 
Method Summary
protected int
convertRowToY(int row)

          Return the JList relative Y coordinate of the origin of the specified row or -1 if row isn't valid.
protected int
convertYToRow(int y0)

          Convert the JList relative coordinate to the row that contains it, based on the current layout.
protected FocusListener

          
protected ListDataListener

          Creates an instance of ListDataListener that's added to the JLists by model as needed.
protected ListSelectionListener

          Creates an instance of ListSelectionHandler that's added to the JLists by selectionModel as needed.
protected MouseInputListener

          Creates a delegate that implements MouseInputListener.
protected PropertyChangeListener

          Creates an instance of PropertyChangeHandler that's added to the JList by installUI().
static ComponentUI

          Returns a new instance of BasicListUI.
 int
getBaseline(JComponent c, int width, int height)

          Returns the baseline.
 Component.BaselineResizeBehavior

          Returns an enum indicating how the baseline of the component changes as the size changes.
 Rectangle
getCellBounds(JList list, int index1, int index2)

          Returns the bounding rectangle, in the given list's coordinate system, for the range of cells specified by the two indices.
 Dimension

          The preferredSize of the list depends upon the layout orientation.
protected int
getRowHeight(int row)

          Returns the height of the specified row based on the current layout.
 Point
indexToLocation(JList list, int index)

          Returns the origin in the given , of the specified item, in the list's coordinate system.
protected void

          Initialize JList properties, e.g.
protected void

          Registers the keyboard bindings on the JList that the BasicListUI is associated with.
protected void

          Create and install the listeners for the JList, its model, and its selectionModel.
 void

          Initializes this.list by calling installDefaults(), installListeners(), and installKeyboardActions() in order.
 int
locationToIndex(JList list, Point location)

          Returns the cell index in the specified closest to the given location in the list's coordinate system.
protected void

          If updateLayoutStateNeeded is non zero, call updateLayoutState() and reset updateLayoutStateNeeded.
 void

          Paint the rows that intersect the Graphics objects clipRect.
protected void
paintCell(Graphics g, int row, Rectangle rowBounds, ListCellRenderer cellRenderer, ListModel dataModel, ListSelectionModel selModel, int leadIndex)

          Paint one List cell: compute the relevant state, get the "rubber stamp" cell renderer component, and then use the CellRendererPane to paint it.
protected void

          Selected the previous row and force it to be visible.
protected void

          Selected the previous row and force it to be visible.
protected void

          Set the JList properties that haven't been explicitly overridden to null.
protected void

          Unregisters keyboard actions installed from installKeyboardActions.
protected void

          Remove the listeners for the JList, its model, and its selectionModel.
 void

          Uninitializes this.list by calling uninstallListeners(), uninstallKeyboardActions(), and uninstallDefaults() in order.
protected void

          Recompute the value of cellHeight or cellHeights based and cellWidth, based on the current font and the current values of fixedCellWidth, fixedCellHeight, and prototypeCellValue.
 
Methods inherited from class javax.swing.plaf.ListUI
getCellBounds, indexToLocation, locationToIndex
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cellHeight

protected int cellHeight

cellHeights

protected int[] cellHeights

cellRendererChanged

protected static final int cellRendererChanged

cellWidth

protected int cellWidth

fixedCellHeightChanged

protected static final int fixedCellHeightChanged

fixedCellWidthChanged

protected static final int fixedCellWidthChanged

focusListener

protected FocusListener focusListener

fontChanged

protected static final int fontChanged

list

protected JList list

listDataListener

protected ListDataListener listDataListener

listSelectionListener

protected ListSelectionListener listSelectionListener

modelChanged

protected static final int modelChanged

mouseInputListener

protected MouseInputListener mouseInputListener

propertyChangeListener

protected PropertyChangeListener propertyChangeListener

prototypeCellValueChanged

protected static final int prototypeCellValueChanged

rendererPane

protected CellRendererPane rendererPane

selectionModelChanged

protected static final int selectionModelChanged

updateLayoutStateNeeded

protected int updateLayoutStateNeeded
Constructor Detail

BasicListUI

public BasicListUI()
Method Detail

convertRowToY

protected int convertRowToY(int row)
Return the JList relative Y coordinate of the origin of the specified row or -1 if row isn't valid.

Parameters:
row
Returns:
The Y coordinate of the origin of row, or -1.

convertYToRow

protected int convertYToRow(int y0)
Convert the JList relative coordinate to the row that contains it, based on the current layout. If y0 doesn't fall within any row, return -1.

Parameters:
y0
Returns:
The row that contains y0, or -1.

createFocusListener

protected FocusListener createFocusListener()

createListDataListener

protected ListDataListener createListDataListener()
Creates an instance of ListDataListener that's added to the JLists by model as needed. Subclasses can override this method to return a custom ListDataListener, e.g.
 class MyListUI extends BasicListUI {
    protected ListDataListener createListDataListener() {
        return new MyListDataListener();
    }
    public class MyListDataListener extends ListDataHandler {
        public void contentsChanged(ListDataEvent e) {
            // do some extra work when the models contents change
            super.contentsChange(e);
        }
    }
 }
 


createListSelectionListener

protected ListSelectionListener createListSelectionListener()
Creates an instance of ListSelectionHandler that's added to the JLists by selectionModel as needed. Subclasses can override this method to return a custom ListSelectionListener, e.g.
 class MyListUI extends BasicListUI {
    protected ListSelectionListener createListSelectionListener() {
        return new MySelectionListener();
    }
    public class MySelectionListener extends ListSelectionHandler {
        public void valueChanged(ListSelectionEvent e) {
            // do some extra work when the selection changes
            super.valueChange(e);
        }
    }
 }
 


createMouseInputListener

protected MouseInputListener createMouseInputListener()
Creates a delegate that implements MouseInputListener. The delegate is added to the corresponding java.awt.Component listener lists at installUI() time. Subclasses can override this method to return a custom MouseInputListener, e.g.
 class MyListUI extends BasicListUI {
    protected MouseInputListener createMouseInputListener() {
        return new MyMouseInputHandler();
    }
    public class MyMouseInputHandler extends MouseInputHandler {
        public void mouseMoved(MouseEvent e) {
            // do some extra work when the mouse moves
            super.mouseMoved(e);
        }
    }
 }
 


createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Creates an instance of PropertyChangeHandler that's added to the JList by installUI(). Subclasses can override this method to return a custom PropertyChangeListener, e.g.
 class MyListUI extends BasicListUI {
    protected PropertyChangeListener createPropertyChangeListener() {
        return new MyPropertyChangeListener();
    }
    public class MyPropertyChangeListener extends PropertyChangeHandler {
        public void propertyChange(PropertyChangeEvent e) {
            if (e.getPropertyName().equals("model")) {
                // do some extra work when the model changes
            }
            super.propertyChange(e);
        }
    }
 }
 


createUI

public static ComponentUI createUI(JComponent list)
Returns a new instance of BasicListUI. BasicListUI delegates are allocated one per JList.

Parameters:
list
Returns:
A new ListUI implementation for the Windows look and feel.

getBaseline

public int getBaseline(JComponent c,
                       int width,
                       int height)
Returns the baseline.

Overrides:
getBaseline in class ComponentUI
Parameters:
c
width
height

getBaselineResizeBehavior

public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
Returns an enum indicating how the baseline of the component changes as the size changes.

Overrides:
getBaselineResizeBehavior in class ComponentUI
Parameters:
c

getCellBounds

public Rectangle getCellBounds(JList list,
                               int index1,
                               int index2)
{@inheritDoc}

Overrides:
getCellBounds in class ListUI
Parameters:
list
index1
index2

getPreferredSize

public Dimension getPreferredSize(JComponent c)
The preferredSize of the list depends upon the layout orientation.
Layout OrientationPreferred Size
JList.VERTICAL The preferredSize of the list is total height of the rows and the maximum width of the cells. If JList.fixedCellHeight is specified then the total height of the rows is just (cellVerticalMargins + fixedCellHeight) * model.getSize() where rowVerticalMargins is the space we allocate for drawing the yellow focus outline. Similarly if fixedCellWidth is specified then we just use that.
JList.VERTICAL_WRAP If the visible row count is greater than zero, the preferredHeight is the maximum cell height * visibleRowCount. If the visible row count is <= 0, the preferred height is either the current height of the list, or the maximum cell height, whichever is bigger. The preferred width is than the maximum cell width * number of columns needed. Where the number of columns needs is list.height / max cell height. Max cell height is either the fixed cell height, or is determined by iterating through all the cells to find the maximum height from the ListCellRenderer.
JList.HORIZONTAL_WRAP If the visible row count is greater than zero, the preferredHeight is the maximum cell height * adjustedRowCount. Where visibleRowCount is used to determine the number of columns. Because this lays out horizontally the number of rows is then determined from the column count. For example, lets say you have a model with 10 items and the visible row count is 8. The number of columns needed to display this is 2, but you no longer need 8 rows to display this, you only need 5, thus the adjustedRowCount is 5.

If the visible row count is <= 0, the preferred height is dictated by the number of columns, which will be as many as can fit in the width of the JList (width / max cell width), with at least one column. The preferred height then becomes the model size / number of columns * maximum cell height. Max cell height is either the fixed cell height, or is determined by iterating through all the cells to find the maximum height from the ListCellRenderer.

The above specifies the raw preferred width and height. The resulting preferred width is the above width + insets.left + insets.right and the resulting preferred height is the above height + insets.top + insets.bottom. Where the Insets are determined from list.getInsets().

Overrides:
getPreferredSize in class ComponentUI
Parameters:
c - The JList component.
Returns:
The total size of the list.

getRowHeight

protected int getRowHeight(int row)
Returns the height of the specified row based on the current layout.

Parameters:
row
Returns:
The specified row height or -1 if row isn't valid.

indexToLocation

public Point indexToLocation(JList list,
                             int index)
{@inheritDoc}

Overrides:
indexToLocation in class ListUI
Parameters:
list
index

installDefaults

protected void installDefaults()
Initialize JList properties, e.g. font, foreground, and background, and add the CellRendererPane. The font, foreground, and background properties are only set if their current value is either null or a UIResource, other properties are set if the current value is null.


installKeyboardActions

protected void installKeyboardActions()
Registers the keyboard bindings on the JList that the BasicListUI is associated with. This method is called at installUI() time.


installListeners

protected void installListeners()
Create and install the listeners for the JList, its model, and its selectionModel. This method is called at installUI() time.


installUI

public void installUI(JComponent c)
Initializes this.list by calling installDefaults(), installListeners(), and installKeyboardActions() in order.

Overrides:
installUI in class ComponentUI
Parameters:
c

locationToIndex

public int locationToIndex(JList list,
                           Point location)
{@inheritDoc}

Overrides:
locationToIndex in class ListUI
Parameters:
list
location

maybeUpdateLayoutState

protected void maybeUpdateLayoutState()
If updateLayoutStateNeeded is non zero, call updateLayoutState() and reset updateLayoutStateNeeded. This method should be called by methods before doing any computation based on the geometry of the list. For example it's the first call in paint() and getPreferredSize().


paint

public void paint(Graphics g,
                  JComponent c)
Paint the rows that intersect the Graphics objects clipRect. This method calls paintCell as necessary. Subclasses may want to override these methods.

Overrides:
paint in class ComponentUI
Parameters:
g
c

paintCell

protected void paintCell(Graphics g,
                         int row,
                         Rectangle rowBounds,
                         ListCellRenderer cellRenderer,
                         ListModel dataModel,
                         ListSelectionModel selModel,
                         int leadIndex)
Paint one List cell: compute the relevant state, get the "rubber stamp" cell renderer component, and then use the CellRendererPane to paint it. Subclasses may want to override this method rather than paint().

Parameters:
g
row
rowBounds
cellRenderer
dataModel
selModel
leadIndex

selectNextIndex

protected void selectNextIndex()
Selected the previous row and force it to be visible.


selectPreviousIndex

protected void selectPreviousIndex()
Selected the previous row and force it to be visible.


uninstallDefaults

protected void uninstallDefaults()
Set the JList properties that haven't been explicitly overridden to null. A property is considered overridden if its current value is not a UIResource.


uninstallKeyboardActions

protected void uninstallKeyboardActions()
Unregisters keyboard actions installed from installKeyboardActions. This method is called at uninstallUI() time - subclassess should ensure that all of the keyboard actions registered at installUI time are removed here.


uninstallListeners

protected void uninstallListeners()
Remove the listeners for the JList, its model, and its selectionModel. All of the listener fields, are reset to null here. This method is called at uninstallUI() time, it should be kept in sync with installListeners.


uninstallUI

public void uninstallUI(JComponent c)
Uninitializes this.list by calling uninstallListeners(), uninstallKeyboardActions(), and uninstallDefaults() in order. Sets this.list to null.

Overrides:
uninstallUI in class ComponentUI
Parameters:
c

updateLayoutState

protected void updateLayoutState()
Recompute the value of cellHeight or cellHeights based and cellWidth, based on the current font and the current values of fixedCellWidth, fixedCellHeight, and prototypeCellValue.



This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.