java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.ListUI
javax.swing.plaf.basic.BasicListUI
- 直接已知的子类:
-
SynthListUI
ListUI的可扩展实现。
BasicListUI实例不能在多个列表之间共享。
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass此类应被视为“protected”内部类。class在installUI时间向JLists模型添加的ListDataListener,以及每当JList.model属性更改时。class在installUI时间向JLists选择模型添加的ListSelectionListener,以及每当JList.selectionModel属性更改时。classJList的鼠标输入和焦点处理。class在installUI时间向JList添加的PropertyChangeListener。 -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int单元格的高度。protected int[]单元格高度的数组protected static final int与单元格渲染器更改属性相关的位。protected int单元格的宽度。protected static final int与固定单元格高度更改属性相关的位。protected static final int与固定单元格宽度更改属性相关的位。protected FocusListener附加到JList的FocusListener。protected static final int与字体更改属性相关的位。JList的实例。protected ListDataListener附加到JList的ListDataListener。protected ListSelectionListener附加到JList的ListSelectionListener。protected static final int与模型更改属性相关的位。protected MouseInputListener附加到JList的MouseInputListener。protected PropertyChangeListener附加到JList的PropertyChangeListener。protected static final int与原型单元格值更改属性相关的位。protected CellRendererPaneCellRendererPane的实例。protected static final int与选择模型更改属性相关的位。protected int代表JList模型的更改。 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intconvertRowToY(int row) 返回指定行的JList相对Y坐标的原点,如果行无效则返回-1。protected intconvertYToRow(int y0) 根据当前布局,将JList相对坐标转换为包含它的行。protected FocusListener返回FocusListener的实例。protected ListDataListener创建一个ListDataListener的实例,根据需要将其添加到JLists中的模型中。protected ListSelectionListener创建一个ListSelectionHandler的实例,根据需要将其添加到JLists中的选择模型中。protected MouseInputListener创建一个实现MouseInputListener的委托。protected PropertyChangeListener创建一个PropertyChangeHandler的实例,根据需要将其添加到JList中的installUI()中。static ComponentUIcreateUI(JComponent list) 返回一个新的BasicListUI实例。intgetBaseline(JComponent c, int width, int height) 返回基线。返回一个枚举,指示组件的基线随着大小变化而变化的方式。getCellBounds(JList<?> list, int index1, int index2) 返回给定列表坐标系中指定索引范围的边界矩形。列表的preferredSize取决于布局方向。protected intgetRowHeight(int row) 根据当前布局返回指定行的高度。indexToLocation(JList<?> list, int index) 返回给定JList中指定项目的原点,以列表的坐标系为基础。protected void初始化列表属性,如字体、前景色和背景色,并添加CellRendererPane。protected void在与BasicListUI关联的JList上注册键盘绑定。protected void为JList及其模型和选择模型创建并安装监听器。void通过按顺序调用installDefaults()、installListeners()和installKeyboardActions()来初始化this.list。intlocationToIndex(JList<?> list, Point location) 返回与列表坐标系中给定位置最接近的指定JList中的单元格索引。protected void如果updateLayoutStateNeeded非零,则调用updateLayoutState()并重置updateLayoutStateNeeded。voidpaint(Graphics g, JComponent c) 绘制与Graphics对象clipRect相交的行。protected voidpaintCell(Graphics g, int row, Rectangle rowBounds, ListCellRenderer<Object> cellRenderer, ListModel<Object> dataModel, ListSelectionModel selModel, int leadIndex) 绘制一个列表单元格:计算相关状态,获取“橡皮图章”单元格渲染器组件,然后使用CellRendererPane进行绘制。protected void选择前一行并强制使其可见。protected void选择前一行并强制使其可见。protected void将未明确覆盖的列表属性设置为null。protected void注销从installKeyboardActions安装的键盘操作。protected void从JList、其模型和选择模型中删除监听器。void通过按顺序调用uninstallListeners()、uninstallKeyboardActions()和uninstallDefaults()来取消初始化this.list。protected void根据当前字体和fixedCellWidth、fixedCellHeight和prototypeCellValue的当前值,重新计算cellHeight或cellHeights和cellWidth的值。Methods declared in class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, update
-
Field Details
-
list
JList的实例。 -
rendererPane
CellRendererPane的实例。 -
focusListener
附加到JList的FocusListener。 -
mouseInputListener
附加到JList的MouseInputListener。 -
listSelectionListener
附加到JList的ListSelectionListener。 -
listDataListener
附加到JList的ListDataListener。 -
propertyChangeListener
附加到JList的PropertyChangeListener。 -
cellHeights
protected int[] cellHeights单元格高度的数组 -
cellHeight
protected int cellHeight单元格的高度。 -
cellWidth
protected int cellWidth单元格的宽度。 -
updateLayoutStateNeeded
protected int updateLayoutStateNeeded代表JList模型的更改。 -
modelChanged
protected static final int modelChanged与模型更改属性相关的位。- 参见:
-
selectionModelChanged
protected static final int selectionModelChanged与选择模型更改属性相关的位。- 参见:
-
fontChanged
protected static final int fontChanged与字体更改属性相关的位。- 参见:
-
fixedCellWidthChanged
protected static final int fixedCellWidthChanged与固定单元格宽度更改属性相关的位。- 参见:
-
fixedCellHeightChanged
protected static final int fixedCellHeightChanged与固定单元格高度更改属性相关的位。- 参见:
-
prototypeCellValueChanged
protected static final int prototypeCellValueChanged与原型单元格值更改属性相关的位。- 参见:
-
cellRendererChanged
protected static final int cellRendererChanged与单元格渲染器更改属性相关的位。- 参见:
-
-
Constructor Details
-
BasicListUI
public BasicListUI()构造一个BasicListUI。
-
-
Method Details
-
paintCell
protected void paintCell(Graphics g, int row, Rectangle rowBounds, ListCellRenderer<Object> cellRenderer, ListModel<Object> dataModel, ListSelectionModel selModel, int leadIndex) 绘制一个列表单元格:计算相关状态,获取“橡皮图章”单元格渲染器组件,然后使用CellRendererPane进行绘制。子类可能希望重写此方法而不是paint()。- 参数:
-
g-Graphics的一个实例 -
row- 一行 -
rowBounds- 要渲染的边界矩形 -
cellRenderer-ListCellRenderer的列表 -
dataModel- 列表模型 -
selModel- 选择模型 -
leadIndex- lead索引 - 参见:
-
paint
绘制与Graphics对象clipRect相交的行。必要时调用paintCell。子类可能希望重写这些方法。- 覆盖:
-
paint在类ComponentUI中 - 参数:
-
g- 要绘制的Graphics上下文 -
c- 正在绘制的组件;此参数通常被忽略,但如果UI对象是无状态的并且由多个组件共享,则可能会使用 - 参见:
-
getBaseline
返回基线。- 覆盖:
-
getBaseline在类ComponentUI - 参数:
-
c- 请求基线的JComponent -
width- 获取基线的宽度 -
height- 获取基线的高度 - 返回:
- 基线或值<0,表示没有合理的基线
- 抛出:
-
NullPointerException- 如果c为null -
IllegalArgumentException- 如果宽度或高度<0 - 自:
- 1.6
- 参见:
-
getBaselineResizeBehavior
返回一个枚举,指示组件的基线随大小变化而变化的方式。- 覆盖:
-
getBaselineResizeBehavior在类ComponentUI - 参数:
-
c- 要返回基线调整行为的JComponent - 返回:
- 一个枚举,指示基线随组件大小变化而变化的方式
- 抛出:
-
NullPointerException- 如果c为null - 自:
- 1.6
- 参见:
-
getPreferredSize
列表的preferredSize取决于布局方向。
上述指定了原始preferred宽度和高度。结果的preferred宽度是上述宽度+ insets.left + insets.right,结果的preferred高度是上述高度+ insets.top + insets.bottom。其中描述每个布局方向的preferred size 布局方向 Preferred Size JList.VERTICAL 列表的preferredSize是行的总高度和单元格的最大宽度。如果指定了JList.fixedCellHeight,则行的总高度只是(cellVerticalMargins + fixedCellHeight)* model.getSize(),其中rowVerticalMargins是我们为绘制黄色焦点轮廓分配的空间。类似地,如果指定了fixedCellWidth,则我们只使用那个宽度。 JList.VERTICAL_WRAP 如果可见行数大于零,则preferredHeight是最大单元格高度* visibleRowCount。如果可见行数<= 0,则preferred height是列表的当前高度或最大单元格高度中较大的一个。首选宽度是所需列数的最大单元格宽度*。所需的列数是list.height / max cell height。最大单元格高度是固定单元格高度,或者通过迭代所有单元格找到ListCellRenderer中的最大高度确定的。 JList.HORIZONTAL_WRAP 如果可见行数大于零,则preferredHeight是最大单元格高度* adjustedRowCount。其中visibleRowCount用于确定列数。因为这是水平布局,所以行数是从列数确定的。例如,假设您有一个包含10个项目的模型,可见行数为8。显示此内容所需的列数为2,但您不再需要8行来显示此内容,只需要5行,因此adjustedRowCount为5。 如果可见行数<= 0,则首选高度由列数决定,这些列数将尽可能多地适合
JList的宽度(宽度/最大单元格宽度),至少有一列。然后,首选高度变为模型大小/列数*最大单元格高度。最大单元格高度是固定单元格高度,或者通过迭代所有单元格找到ListCellRenderer中的最大高度确定的。Insets是从list.getInsets()确定的。- 覆盖:
-
getPreferredSize在类ComponentUI - 参数:
-
c- JList组件。 - 返回:
- 列表的总大小。
- 参见:
-
selectPreviousIndex
protected void selectPreviousIndex()选择前一行并强制使其可见。- 参见:
-
selectNextIndex
protected void selectNextIndex()选择前一行并强制使其可见。- 参见:
-
installKeyboardActions
protected void installKeyboardActions()在与BasicListUI关联的JList上注册键盘绑定。此方法在installUI()时调用。- 参见:
-
uninstallKeyboardActions
protected void uninstallKeyboardActions()从installKeyboardActions中卸载安装的键盘操作。此方法在uninstallUI()时调用 - 子类应确保在此处删除在installUI时注册的所有键盘操作。- 参见:
-
installListeners
protected void installListeners()为JList及其模型和selectionModel创建并安装侦听器。此方法在installUI()时调用。- 参见:
-
uninstallListeners
protected void uninstallListeners()从JList及其模型和selectionModel中删除侦听器。所有侦听器字段在此处重置为null。此方法在uninstallUI()时调用,应与installListeners保持同步。- 参见:
-
installDefaults
protected void installDefaults()初始化列表属性,如字体、前景色和背景色,并添加CellRendererPane。仅当它们的当前值为null或UIResource时,才设置字体、前景色和背景色属性,其他属性仅在当前值为null时设置。- 参见:
-
uninstallDefaults
protected void uninstallDefaults()设置未明确覆盖的列表属性为null。如果当前值不是UIResource,则认为属性已被覆盖。- 参见:
-
installUI
通过按顺序调用installDefaults()、installListeners()和installKeyboardActions()来初始化this.list。- 覆盖:
-
installUI在类ComponentUI - 参数:
-
c- 安装此UI委托的组件 - 参见:
-
uninstallUI
通过按顺序调用uninstallListeners()、uninstallKeyboardActions()和uninstallDefaults()来取消初始化this.list。将this.list设置为null。- 覆盖:
-
uninstallUI在类ComponentUI - 参数:
-
c- 正在移除此UI委托的组件;此参数通常被忽略,但如果UI对象是无状态的并且由多个组件共享,则可能会使用该参数 - 参见:
-
createUI
返回BasicListUI的新实例。每个JList分配一个BasicListUI委托。- 参数:
-
list- 一个组件 - 返回:
-
一个适用于Windows外观的新
ListUI实现。
-
locationToIndex
返回指定JList中距离给定位置最近的单元格索引,该位置是列表坐标系中的位置。要确定单元格是否实际包含指定位置,请将该点与单元格的边界进行比较,如getCellBounds提供的那样。如果列表的模型为空,则此方法返回-1。- 指定者:
-
locationToIndex在类ListUI - 参数:
-
list- 列表 -
location- 点的坐标 - 返回:
-
最接近给定位置的单元格索引,或
-1 - 抛出:
-
NullPointerException- 如果location为null
-
indexToLocation
返回给定JList中指定项目的原点,以列表坐标系表示。如果索引无效,则返回null。- 指定者:
-
indexToLocation在类ListUI - 参数:
-
list- 列表 -
index- 单元格索引 - 返回:
-
单元格的原点,或
null
-
getCellBounds
返回给定列表坐标系中由两个索引指定的单元格范围的边界矩形。可以以任何顺序提供索引。如果较小的索引超出列表的单元格范围,则此方法返回
null。如果较小的索引有效,但较大的索引超出列表的范围,则仅返回第一个索引的边界。否则,返回有效范围的边界。- 指定者:
-
getCellBounds在类ListUI - 参数:
-
list- 列表 -
index1- 范围中的第一个索引 -
index2- 范围中的第二个索引 - 返回:
-
单元格范围的边界矩形,或
null
-
getRowHeight
protected int getRowHeight(int row) 返回基于当前布局的指定行的高度。- 参数:
-
row- 一行 - 返回:
- 指定行的高度或-1(如果行无效)
- 参见:
-
convertYToRow
protected int convertYToRow(int y0) 将JList相对坐标转换为包含它的行,基于当前布局。如果y0不在任何行内,则返回-1。- 参数:
-
y0- 相对Y坐标 - 返回:
- 包含y0的行,或-1
- 参见:
-
convertRowToY
protected int convertRowToY(int row) 返回指定行的原点的JList相对Y坐标,如果行无效则返回-1。- 参数:
-
row- 一行 - 返回:
- 行原点的Y坐标,或-1
- 参见:
-
maybeUpdateLayoutState
protected void maybeUpdateLayoutState()如果updateLayoutStateNeeded非零,则调用updateLayoutState()并重置updateLayoutStateNeeded。在进行基于列表几何形状的任何计算之前,方法应该调用此方法。例如,在paint()和getPreferredSize()中,这是第一个调用。- 参见:
-
updateLayoutState
protected void updateLayoutState()根据当前字体和fixedCellWidth、fixedCellHeight和prototypeCellValue的当前值,重新计算cellHeight或cellHeights的值。- 参见:
-
createMouseInputListener
创建一个实现MouseInputListener的委托。在installUI()时,将委托添加到相应的java.awt.Component监听器列表中。子类可以重写此方法返回自定义的MouseInputListener,例如class MyListUI extends BasicListUI { protected MouseInputListener createMouseInputListener() { return new MyMouseInputHandler(); } public class MyMouseInputHandler extends MouseInputHandler { public void mouseMoved(MouseEvent e) { // 鼠标移动时执行一些额外操作 super.mouseMoved(e); } } }- 返回:
-
一个
MouseInputListener的实例 - 参见:
-
createFocusListener
返回一个FocusListener的实例。- 返回:
-
一个
FocusListener的实例
-
createListSelectionListener
创建一个实现ListSelectionHandler的实例,根据需要将其添加到JLists的选择模型中。子类可以重写此方法返回自定义的ListSelectionListener,例如class MyListUI extends BasicListUI { protected ListSelectionListener createListSelectionListener() { return new MySelectionListener(); } public class MySelectionListener extends ListSelectionHandler { public void valueChanged(ListSelectionEvent e) { // 选择更改时执行一些额外操作 super.valueChange(e); } } }- 返回:
-
一个
ListSelectionHandler的实例 - 参见:
-
createListDataListener
创建一个实现ListDataListener的实例,根据需要将其添加到JLists的模型中。子类可以重写此方法返回自定义的ListDataListener,例如class MyListUI extends BasicListUI { protected ListDataListener createListDataListener() { return new MyListDataListener(); } public class MyListDataListener extends ListDataHandler { public void contentsChanged(ListDataEvent e) { // 当模型内容更改时执行一些额外操作 super.contentsChange(e); } } }- 返回:
-
一个
ListDataListener的实例 - 参见:
-
createPropertyChangeListener
创建一个实现PropertyChangeHandler的实例,由installUI()添加到JList中。子类可以重写此方法返回自定义的PropertyChangeListener,例如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")) { // 当模型更改时执行一些额外操作 } super.propertyChange(e); } } }- 返回:
-
一个
PropertyChangeHandler的实例 - 参见:
-