Class BasicListUI
- Direct Known Subclasses:
- SynthListUI
ListUI.
 
 BasicListUI instances cannot be shared between multiple
 lists.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionclassThis class should be treated as a "protected" inner class.classTheListDataListenerthat's added to theJListsmodel atinstallUI time, and whenever the JList.model property changes.classThe ListSelectionListener that's added to the JLists selection model at installUI time, and whenever the JList.selectionModel property changes.classMouse input, and focus handling for JList.classThe PropertyChangeListener that's added to the JList at installUI time.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected intThe height of cell.protected int[]The array of cells' heightprotected static final intThe bit relates to cell renderer changed property.protected intThe width of cell.protected static final intThe bit relates to fixed cell height changed property.protected static final intThe bit relates to fixed cell width changed property.protected FocusListenerFocusListenerthat attached toJList.protected static final intThe bit relates to font changed property.The instance ofJList.protected ListDataListenerListDataListenerthat attached toJList.protected ListSelectionListenerListSelectionListenerthat attached toJList.protected static final intThe bit relates to model changed property.protected MouseInputListenerMouseInputListenerthat attached toJList.protected PropertyChangeListenerPropertyChangeListenerthat attached toJList.protected static final intThe bit relates to prototype cell value changed property.protected CellRendererPaneThe instance ofCellRendererPane.protected static final intThe bit relates to selection model changed property.protected intThe value represents changes toJListmodel.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected intconvertRowToY(int row) Return theJListrelative Y coordinate of the origin of the specified row or -1 if row isn't valid.protected intconvertYToRow(int y0) Convert theJListrelative coordinate to the row that contains it, based on the current layout.protected FocusListenerReturns an instance ofFocusListener.protected ListDataListenerCreates an instance ofListDataListenerthat's added to theJListsby model as needed.protected ListSelectionListenerCreates an instance ofListSelectionHandlerthat's added to theJListsby selectionModel as needed.protected MouseInputListenerCreates a delegate that implementsMouseInputListener.protected PropertyChangeListenerCreates an instance ofPropertyChangeHandlerthat's added to theJListbyinstallUI().static ComponentUIcreateUI(JComponent list) Returns a new instance ofBasicListUI.intgetBaseline(JComponent c, int width, int height) Returns the baseline.Returns an enum indicating how the baseline of the component changes as the size changes.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.The preferredSize of the list depends upon the layout orientation.protected intgetRowHeight(int row) Returns the height of the specified row based on the current layout.indexToLocation(JList<?> list, int index) Returns the origin in the givenJList, of the specified item, in the list's coordinate system.protected voidInitializes list properties such as font, foreground, and background, and adds the CellRendererPane.protected voidRegisters the keyboard bindings on theJListthat theBasicListUIis associated with.protected voidCreates and installs the listeners for the JList, its model, and its selectionModel.voidInitializesthis.listby callinginstallDefaults(),installListeners(), andinstallKeyboardActions()in order.intlocationToIndex(JList<?> list, Point location) Returns the cell index in the specifiedJListclosest to the given location in the list's coordinate system.protected voidIf updateLayoutStateNeeded is non zero, call updateLayoutState() and reset updateLayoutStateNeeded.voidpaint(Graphics g, JComponent c) Paint the rows that intersect the Graphics objects clipRect.protected voidpaintCell(Graphics g, int row, Rectangle rowBounds, ListCellRenderer<Object> cellRenderer, ListModel<Object> dataModel, ListSelectionModel selModel, int leadIndex) Paint one List cell: compute the relevant state, get the "rubber stamp" cell renderer component, and then use theCellRendererPaneto paint it.protected voidSelected the previous row and force it to be visible.protected voidSelected the previous row and force it to be visible.protected voidSets the list properties that have not been explicitly overridden tonull.protected voidUnregisters keyboard actions installed frominstallKeyboardActions.protected voidRemoves the listeners from the JList, its model, and its selectionModel.voidUninitializesthis.listby callinguninstallListeners(),uninstallKeyboardActions(), anduninstallDefaults()in order.protected voidRecompute the value of cellHeight or cellHeights based and cellWidth, based on the current font and the current values of fixedCellWidth, fixedCellHeight, and prototypeCellValue.Methods declared in class javax.swing.plaf.ComponentUIcontains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, update
- 
Field Details- 
list
- 
rendererPaneThe instance ofCellRendererPane.
- 
focusListenerFocusListenerthat attached toJList.
- 
mouseInputListenerMouseInputListenerthat attached toJList.
- 
listSelectionListenerListSelectionListenerthat attached toJList.
- 
listDataListenerListDataListenerthat attached toJList.
- 
propertyChangeListenerPropertyChangeListenerthat attached toJList.
- 
cellHeightsprotected int[] cellHeightsThe array of cells' height
- 
cellHeightprotected int cellHeightThe height of cell.
- 
cellWidthprotected int cellWidthThe width of cell.
- 
updateLayoutStateNeededprotected int updateLayoutStateNeededThe value represents changes toJListmodel.
- 
modelChangedprotected static final int modelChangedThe bit relates to model changed property.- See Also:
 
- 
selectionModelChangedprotected static final int selectionModelChangedThe bit relates to selection model changed property.- See Also:
 
- 
fontChangedprotected static final int fontChangedThe bit relates to font changed property.- See Also:
 
- 
fixedCellWidthChangedprotected static final int fixedCellWidthChangedThe bit relates to fixed cell width changed property.- See Also:
 
- 
fixedCellHeightChangedprotected static final int fixedCellHeightChangedThe bit relates to fixed cell height changed property.- See Also:
 
- 
prototypeCellValueChangedprotected static final int prototypeCellValueChangedThe bit relates to prototype cell value changed property.- See Also:
 
- 
cellRendererChangedprotected static final int cellRendererChangedThe bit relates to cell renderer changed property.- See Also:
 
 
- 
- 
Constructor Details- 
BasicListUIpublic BasicListUI()Constructs aBasicListUI.
 
- 
- 
Method Details- 
paintCellprotected void paintCell(Graphics g, int row, Rectangle rowBounds, ListCellRenderer<Object> cellRenderer, ListModel<Object> dataModel, ListSelectionModel selModel, int leadIndex) Paint one List cell: compute the relevant state, get the "rubber stamp" cell renderer component, and then use theCellRendererPaneto paint it. Subclasses may want to override this method rather thanpaint().- Parameters:
- g- an instance of- Graphics
- row- a row
- rowBounds- a bounding rectangle to render to
- cellRenderer- a list of- ListCellRenderer
- dataModel- a list model
- selModel- a selection model
- leadIndex- a lead index
- See Also:
 
- 
paintPaint the rows that intersect the Graphics objects clipRect. This method calls paintCell as necessary. Subclasses may want to override these methods.- Overrides:
- paintin class- ComponentUI
- Parameters:
- g- the- Graphicscontext in which to paint
- c- the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
- See Also:
 
- 
getBaselineReturns the baseline.- Overrides:
- getBaselinein class- ComponentUI
- Parameters:
- c-- JComponentbaseline is being requested for
- width- the width to get the baseline for
- height- the height to get the baseline for
- Returns:
- baseline or a value < 0 indicating there is no reasonable baseline
- Throws:
- NullPointerException- if- cis- null
- IllegalArgumentException- if width or height is < 0
- Since:
- 1.6
- See Also:
 
- 
getBaselineResizeBehaviorReturns an enum indicating how the baseline of the component changes as the size changes.- Overrides:
- getBaselineResizeBehaviorin class- ComponentUI
- Parameters:
- c-- JComponentto return baseline resize behavior for
- Returns:
- an enum indicating how the baseline changes as the component size changes
- Throws:
- NullPointerException- if- cis- null
- Since:
- 1.6
- See Also:
 
- 
getPreferredSizeThe preferredSize of the list depends upon the layout orientation.
 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 theDescribes the preferred size for each layout orientation Layout Orientation Preferred 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.Insetsare determined fromlist.getInsets().- Overrides:
- getPreferredSizein class- ComponentUI
- Parameters:
- c- The JList component.
- Returns:
- The total size of the list.
- See Also:
 
- 
selectPreviousIndexprotected void selectPreviousIndex()Selected the previous row and force it to be visible.- See Also:
 
- 
selectNextIndexprotected void selectNextIndex()Selected the previous row and force it to be visible.- See Also:
 
- 
installKeyboardActionsprotected void installKeyboardActions()Registers the keyboard bindings on theJListthat theBasicListUIis associated with. This method is called at installUI() time.- See Also:
 
- 
uninstallKeyboardActionsprotected void uninstallKeyboardActions()Unregisters keyboard actions installed frominstallKeyboardActions. This method is called at uninstallUI() time - subclassess should ensure that all of the keyboard actions registered at installUI time are removed here.- See Also:
 
- 
installListenersprotected void installListeners()Creates and installs the listeners for the JList, its model, and its selectionModel. This method is called at installUI() time.- See Also:
 
- 
uninstallListenersprotected void uninstallListeners()Removes the listeners from 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.- See Also:
 
- 
installDefaultsprotected void installDefaults()Initializes list properties such as font, foreground, and background, and adds 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.- See Also:
 
- 
uninstallDefaultsprotected void uninstallDefaults()Sets the list properties that have not been explicitly overridden tonull. A property is considered overridden if its current value is not aUIResource.- See Also:
 
- 
installUIInitializesthis.listby callinginstallDefaults(),installListeners(), andinstallKeyboardActions()in order.- Overrides:
- installUIin class- ComponentUI
- Parameters:
- c- the component where this UI delegate is being installed
- See Also:
 
- 
uninstallUIUninitializesthis.listby callinguninstallListeners(),uninstallKeyboardActions(), anduninstallDefaults()in order. Sets this.list to null.- Overrides:
- uninstallUIin class- ComponentUI
- Parameters:
- c- the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
- See Also:
 
- 
createUIReturns a new instance ofBasicListUI.BasicListUIdelegates are allocated one perJList.- Parameters:
- list- a component
- Returns:
- a new ListUIimplementation for the Windows look and feel.
 
- 
locationToIndexReturns the cell index in the specifiedJListclosest to the given location in the list's coordinate system. To determine if the cell actually contains the specified location, compare the point against the cell's bounds, as provided bygetCellBounds. This method returns-1if the list's model is empty.- Specified by:
- locationToIndexin class- ListUI
- Parameters:
- list- the list
- location- the coordinates of the point
- Returns:
- the cell index closest to the given location, or -1
- Throws:
- NullPointerException- if- locationis null
 
- 
indexToLocationReturns the origin in the givenJList, of the specified item, in the list's coordinate system. Returnsnullif the index isn't valid.- Specified by:
- indexToLocationin class- ListUI
- Parameters:
- list- the list
- index- the cell index
- Returns:
- the origin of the cell, or null
 
- 
getCellBoundsReturns the bounding rectangle, in the given list's coordinate system, for the range of cells specified by the two indices. The indices can be supplied in any order.If the smaller index is outside the list's range of cells, this method returns null. If the smaller index is valid, but the larger index is outside the list's range, the bounds of just the first index is returned. Otherwise, the bounds of the valid range is returned.- Specified by:
- getCellBoundsin class- ListUI
- Parameters:
- list- the list
- index1- the first index in the range
- index2- the second index in the range
- Returns:
- the bounding rectangle for the range of cells, or null
 
- 
getRowHeightprotected int getRowHeight(int row) Returns the height of the specified row based on the current layout.- Parameters:
- row- a row
- Returns:
- the specified row height or -1 if row isn't valid
- See Also:
 
- 
convertYToRowprotected int convertYToRow(int y0) Convert theJListrelative coordinate to the row that contains it, based on the current layout. Ify0doesn't fall within any row, return -1.- Parameters:
- y0- a relative Y coordinate
- Returns:
- the row that contains y0, or -1
- See Also:
 
- 
convertRowToYprotected int convertRowToY(int row) Return theJListrelative Y coordinate of the origin of the specified row or -1 if row isn't valid.- Parameters:
- row- a row
- Returns:
- the Y coordinate of the origin of row, or -1
- See Also:
 
- 
maybeUpdateLayoutStateprotected 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().- See Also:
 
- 
updateLayoutStateprotected 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.- See Also:
 
- 
createMouseInputListenerCreates a delegate that implementsMouseInputListener. The delegate is added to the correspondingjava.awt.Componentlistener lists atinstallUI()time. Subclasses can override this method to return a customMouseInputListener, 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); } } }- Returns:
- an instance of MouseInputListener
- See Also:
 
- 
createFocusListenerReturns an instance ofFocusListener.- Returns:
- an instance of FocusListener
 
- 
createListSelectionListenerCreates an instance ofListSelectionHandlerthat's added to theJListsby selectionModel as needed. Subclasses can override this method to return a customListSelectionListener, 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); } } }- Returns:
- an instance of ListSelectionHandler
- See Also:
 
- 
createListDataListenerCreates an instance ofListDataListenerthat's added to theJListsby model as needed. Subclasses can override this method to return a customListDataListener, 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); } } }- Returns:
- an instance of ListDataListener
- See Also:
 
- 
createPropertyChangeListenerCreates an instance ofPropertyChangeHandlerthat's added to theJListbyinstallUI(). Subclasses can override this method to return a customPropertyChangeListener, 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); } } }- Returns:
- an instance of PropertyChangeHandler
- See Also:
 
 
-