java.lang.Object | |||
↳ | javax.swing.plaf.ComponentUI | ||
↳ | javax.swing.plaf.ListUI | ||
↳ | javax.swing.plaf.basic.BasicListUI |
An extensible implementation of ListUI
.
BasicListUI
instances cannot be shared between multiple
lists.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
BasicListUI.FocusHandler | This inner class is marked "public" due to a compiler bug. | ||||||||||
BasicListUI.ListDataHandler | The ListDataListener that's added to the JLists model at installUI time, and whenever the JList.model property changes. | ||||||||||
BasicListUI.ListSelectionHandler | The ListSelectionListener that's added to the JLists selection model at installUI time, and whenever the JList.selectionModel property changes. | ||||||||||
BasicListUI.MouseInputHandler | Mouse input, and focus handling for JList. | ||||||||||
BasicListUI.PropertyChangeHandler | The PropertyChangeListener that's added to the JList at installUI time. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | cellRendererChanged | ||||||||||
int | fixedCellHeightChanged | ||||||||||
int | fixedCellWidthChanged | ||||||||||
int | fontChanged | ||||||||||
int | modelChanged | ||||||||||
int | prototypeCellValueChanged | ||||||||||
int | selectionModelChanged |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
cellHeight | |||||||||||
cellHeights | |||||||||||
cellWidth | |||||||||||
focusListener | |||||||||||
list | |||||||||||
listDataListener | |||||||||||
listSelectionListener | |||||||||||
mouseInputListener | |||||||||||
propertyChangeListener | |||||||||||
rendererPane | |||||||||||
updateLayoutStateNeeded |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns a new instance of BasicListUI.
| |||||||||||
Returns the baseline.
| |||||||||||
Returns an enum indicating how the baseline of the component
changes as the size changes.
| |||||||||||
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.
| |||||||||||
Returns the origin in the given
JList , of the specified item,
in the list's coordinate system.
| |||||||||||
Initializes
this.list by calling installDefaults() ,
installListeners() , and installKeyboardActions()
in order. | |||||||||||
Returns the cell index in the specified
JList closest to the
given location in the list's coordinate system. | |||||||||||
Paint the rows that intersect the Graphics objects clipRect.
| |||||||||||
Uninitializes
this.list by calling uninstallListeners() ,
uninstallKeyboardActions() , and uninstallDefaults()
in order. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return the JList relative Y coordinate of the origin of the specified
row or -1 if row isn't valid.
| |||||||||||
Convert the JList relative coordinate to the row that contains it,
based on the current layout.
| |||||||||||
Creates an instance of ListDataListener that's added to
the JLists by model as needed.
| |||||||||||
Creates an instance of ListSelectionHandler that's added to
the JLists by selectionModel as needed.
| |||||||||||
Creates a delegate that implements MouseInputListener.
| |||||||||||
Creates an instance of PropertyChangeHandler that's added to
the JList by installUI().
| |||||||||||
Returns the height of the specified row based on the current layout.
| |||||||||||
Initialize JList properties, e.g.
| |||||||||||
Registers the keyboard bindings on the
JList that the
BasicListUI is associated with. | |||||||||||
Create and install the listeners for the JList, its model, and its
selectionModel.
| |||||||||||
If updateLayoutStateNeeded is non zero, call updateLayoutState() and reset
updateLayoutStateNeeded.
| |||||||||||
Paint one List cell: compute the relevant state, get the "rubber stamp"
cell renderer component, and then use the CellRendererPane to paint it.
| |||||||||||
Selected the previous row and force it to be visible.
| |||||||||||
Selected the previous row and force it to be visible.
| |||||||||||
Set the JList properties that haven't been explicitly overridden to
null.
| |||||||||||
Unregisters keyboard actions installed from
installKeyboardActions . | |||||||||||
Remove the listeners for the JList, its model, and its
selectionModel.
| |||||||||||
Recompute the value of cellHeight or cellHeights based
and cellWidth, based on the current font and the current
values of fixedCellWidth, fixedCellHeight, and prototypeCellValue.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() |
Returns a new instance of BasicListUI. BasicListUI delegates are allocated one per JList.
Returns the baseline.
c | JComponent baseline is being requested for |
---|---|
width | the width to get the baseline for |
height | the height to get the baseline for |
Returns an enum indicating how the baseline of the component changes as the size changes.
c | JComponent to return baseline resize behavior for |
---|
NullPointerException |
---|
Returns 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.
list | the list |
---|---|
index1 | the first index in the range |
index2 | the second index in the range |
null
The preferredSize of the list depends upon the 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 |
Insets
are determined from
list.getInsets()
.c | The JList component. |
---|
Returns the origin in the given JList
, of the specified item,
in the list's coordinate system.
Returns null
if the index isn't valid.
list | the list |
---|---|
index | the cell index |
null
Initializes this.list
by calling installDefaults()
,
installListeners()
, and installKeyboardActions()
in order.
c | the component where this UI delegate is being installed |
---|
Returns the cell index in the specified JList
closest 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 by getCellBounds
.
This method returns -1
if the list's model is empty.
list | the list |
---|---|
location | the coordinates of the point |
-1
NullPointerException |
---|
Paint the rows that intersect the Graphics objects clipRect. This method calls paintCell as necessary. Subclasses may want to override these methods.
g | the Graphics context 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 |
Uninitializes this.list
by calling uninstallListeners()
,
uninstallKeyboardActions()
, and uninstallDefaults()
in order. Sets this.list to null.
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 |
---|
Return the JList relative Y coordinate of the origin of the specified row or -1 if row isn't valid.
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.
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); } } }
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); } } }
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); } } }
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); } } }
Returns the height of the specified row based on the current layout.
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.
Registers the keyboard bindings on the JList
that the
BasicListUI
is associated with. This method is called at
installUI() time.
Create and install the listeners for the JList, its model, and its selectionModel. This method is called at installUI() time.
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 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().
Selected the previous row and force it to be visible.
Selected the previous row and force it to be visible.
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.
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.
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.
Recompute the value of cellHeight or cellHeights based and cellWidth, based on the current font and the current values of fixedCellWidth, fixedCellHeight, and prototypeCellValue.