- java.lang.Object
-
- javax.swing.plaf.ComponentUI
-
- javax.swing.plaf.ListUI
-
- javax.swing.plaf.basic.BasicListUI
-
- 已知直接子类:
-
SynthListUI
public class BasicListUI extends ListUI
ListUI的可扩展实现。BasicListUI实例不能在多个列表之间共享。
-
-
嵌套类汇总
嵌套类 变量和类型 类 描述 classBasicListUI.FocusHandler该类应被视为“受保护”的内部类。classBasicListUI.ListDataHandlerListDataListener已添加到JLists模型,位于installUI time,并且每当JList.model属性更改时。classBasicListUI.ListSelectionHandler在installUI时添加到JLists选择模型的ListSelectionListener,以及每当JList.selectionModel属性更改时。classBasicListUI.MouseInputHandler鼠标输入和JList的焦点处理。classBasicListUI.PropertyChangeHandler在installUI时添加到JList的PropertyChangeListener。
-
字段汇总
字段 变量和类型 字段 描述 protected intcellHeight细胞的高度。protected int[]cellHeights细胞阵列的高度protected static intcellRendererChanged该位与单元格渲染器更改属性有关。protected intcellWidth细胞的宽度。protected static intfixedCellHeightChanged该位涉及固定单元高度变化的属性。protected static intfixedCellWidthChanged该位涉及固定单元宽度变化的属性。protected FocusListenerfocusListenerFocusListener,附于JList。protected static intfontChanged该位与字体更改属性有关。protected JList<Object>listJList的实例。protected ListDataListenerlistDataListenerListDataListener附于JList。protected ListSelectionListenerlistSelectionListenerListSelectionListener,附于JList。protected static intmodelChanged该位与模型更改属性有关。protected MouseInputListenermouseInputListenerMouseInputListener,附于JList。protected PropertyChangeListenerpropertyChangeListenerPropertyChangeListener,附于JList。protected static intprototypeCellValueChanged该位涉及原型单元值更改的属性。protected CellRendererPanerendererPaneCellRendererPane的实例。protected static intselectionModelChanged该位与选择模型更改的属性有关。protected intupdateLayoutStateNeeded该值表示对JList型号的更改。
-
构造方法摘要
构造方法 构造器 描述 BasicListUI()
-
方法摘要
所有方法 静态方法 实例方法 具体的方法 变量和类型 方法 描述 protected intconvertRowToY(int row)返回指定行原点的JList相对Y坐标,如果行无效,则返回-1。protected intconvertYToRow(int y0)根据当前布局,将JList相对坐标转换为包含它的行。protected FocusListenercreateFocusListener()返回FocusListener的实例。protected ListDataListenercreateListDataListener()创建ListDataListener的实例,根据需要按模型添加到JLists。protected ListSelectionListenercreateListSelectionListener()根据需要JLists由selectionModel添加到JLists的ListSelectionHandler的实例。protected MouseInputListenercreateMouseInputListener()创建实现MouseInputListener的委托。protected PropertyChangeListenercreatePropertyChangeListener()创建的实例PropertyChangeHandler了加的JList由installUI()。static ComponentUIcreateUI(JComponent list)返回BasicListUI的新实例。intgetBaseline(JComponent c, int width, int height)返回基线。Component.BaselineResizeBehaviorgetBaselineResizeBehavior(JComponent c)返回一个枚举,指示组件的基线如何随大小的变化而变化。DimensiongetPreferredSize(JComponent c)列表的preferredSize取决于布局方向。protected intgetRowHeight(int row)根据当前布局返回指定行的高度。protected voidinstallDefaults()初始化列表属性,如字体,前景和背景,并添加CellRendererPane。protected voidinstallKeyboardActions()在与JList关联的BasicListUI上注册键盘绑定。protected voidinstallListeners()创建并安装JList,其模型及其selectionModel的侦听器。voidinstallUI(JComponent c)初始化this.list拨打installDefaults(),installListeners()和installKeyboardActions()秩序。intlocationToIndex(JList<?> list, Point location)返回最接近列表坐标系中给定位置的指定JList中的单元JList。protected voidmaybeUpdateLayoutState()如果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 voidselectNextIndex()选择前一行并强制它可见。protected voidselectPreviousIndex()选择前一行并强制它可见。protected voiduninstallDefaults()将尚未显式覆盖的列表属性设置为null。protected voiduninstallKeyboardActions()取消注册从installKeyboardActions安装的键盘操作。protected voiduninstallListeners()从JList,其模型及其selectionModel中删除侦听器。voiduninstallUI(JComponent c)取消初始化this.list拨打uninstallListeners(),uninstallKeyboardActions()和uninstallDefaults()秩序。protected voidupdateLayoutState()根据当前字体以及fixedCellWidth,fixedCellHeight和prototypeCellValue的当前值,重新计算cellHeight或cellHeights和cellWidth的值。-
声明方法的类 javax.swing.plaf.ListUI
getCellBounds, indexToLocation
-
声明方法的类 javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, update
-
-
-
-
字段详细信息
-
rendererPane
protected CellRendererPane rendererPane
CellRendererPane的实例。
-
focusListener
protected FocusListener focusListener
FocusListener附于JList。
-
mouseInputListener
protected MouseInputListener mouseInputListener
MouseInputListener,附于JList。
-
listSelectionListener
protected ListSelectionListener listSelectionListener
ListSelectionListener,附于JList。
-
listDataListener
protected ListDataListener listDataListener
ListDataListener,附于JList。
-
propertyChangeListener
protected PropertyChangeListener propertyChangeListener
PropertyChangeListener附于JList。
-
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
该位与单元格渲染器更改属性有关。- 另请参见:
- 常数字段值
-
-
方法详细信息
-
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- 潜在客户指数 - 另请参见:
-
paint(java.awt.Graphics, javax.swing.JComponent)
-
paint
public void paint(Graphics g, JComponent c)
绘制与Graphics对象clipRect相交的行。 此方法根据需要调用paintCell。 子类可能希望覆盖这些方法。- 重写:
-
paint,类ComponentUI - 参数
-
g- 要绘制的Graphics上下文 -
c- 正在绘制的组件; 此参数通常被忽略,但如果UI对象是无状态的并且由多个组件共享,则可以使用此参数 - 另请参见:
-
paintCell(java.awt.Graphics, int, java.awt.Rectangle, javax.swing.ListCellRenderer<java.lang.Object>, javax.swing.ListModel<java.lang.Object>, javax.swing.ListSelectionModel, int)
-
getBaseline
public int getBaseline(JComponent c, int width, int height)
返回基线。- 重写:
-
getBaseline类,ComponentUI - 参数
-
正在申请
c-JComponent基线 -
width- 获取基线的宽度 -
height- 获取基线的高度 - 结果
- 基线或值<0表示没有合理的基线
- 异常
-
NullPointerException- 如果c是null -
IllegalArgumentException- 如果宽度或高度<0 - 从以下版本开始:
- 1.6
- 另请参见:
-
JComponent.getBaseline(int, int)
-
getBaselineResizeBehavior
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
返回一个枚举,指示组件的基线如何随大小的变化而变化。- 重写:
-
getBaselineResizeBehavior类ComponentUI - 参数
-
c-JComponent返回基线调整大小的行为 - 结果
- 一个枚举,指示基线随组件大小的变化而变化的方式
- 异常
-
NullPointerException- 如果c是null - 从以下版本开始:
- 1.6
- 另请参见:
-
JComponent.getBaseline(int, int)
-
getPreferredSize
public Dimension getPreferredSize(JComponent c)
列表的preferredSize取决于布局方向。 Describes 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.
以上指定原始首选宽度和高度。 得到的首选宽度是上面的宽度+ insets.left + insets.right,得到的首选高度是上面的高度+ insets.top + insets.bottom。Insets的确定来自list.getInsets()。- 重写:
-
getPreferredSize类ComponentUI - 参数
-
c- JList组件。 - 结果
- 列表的总大小。
- 另请参见:
-
JComponent.getPreferredSize(),LayoutManager.preferredLayoutSize(java.awt.Container)
-
selectPreviousIndex
protected void selectPreviousIndex()
选择前一行并强制它可见。
-
selectNextIndex
protected void selectNextIndex()
选择前一行并强制它可见。
-
installKeyboardActions
protected void installKeyboardActions()
在与JList关联的BasicListUI上注册键盘绑定。 在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
public void installUI(JComponent c)
初始化this.list拨打installDefaults(),installListeners()和installKeyboardActions()秩序。- 重写:
-
installUI类,ComponentUI - 参数
-
c- 正在安装此UI委托的组件 - 另请参见:
-
installDefaults(),installListeners(),installKeyboardActions()
-
uninstallUI
public void uninstallUI(JComponent c)
取消初始化this.list拨打uninstallListeners(),uninstallKeyboardActions()和uninstallDefaults()秩序。 将this.list设置为null。- 重写:
-
uninstallUI类,ComponentUI - 参数
-
c- 要从中删除此UI委托的组件; 此参数通常被忽略,但如果UI对象是无状态的并且由多个组件共享,则可以使用此参数 - 另请参见:
-
uninstallListeners(),uninstallKeyboardActions(),uninstallDefaults()
-
createUI
public static ComponentUI createUI(JComponent list)
返回BasicListUI的新实例。BasicListUI代表每JList分配一个。- 参数
-
list- 一个组件 - 结果
-
适用于Windows外观的全新
ListUI实现。
-
locationToIndex
public int locationToIndex(JList<?> list, Point location)
返回最接近列表坐标系中给定位置的指定JList中的单元JList。 要确定单元格是否实际包含指定位置,请将该点与单元格的边界进行比较,如getCellBounds。 如果列表的模型为空,则此方法返回-1。- Specified by:
-
locationToIndex类ListUI - 参数
-
list- 该清单 -
location- 该点的坐标 - 结果
-
最接近给定位置的单元
-1,或-1 - 异常
-
NullPointerException- 如果location为空
-
getRowHeight
protected int getRowHeight(int row)
根据当前布局返回指定行的高度。- 参数
-
row- 一排 - 结果
- 指定的行高,如果行无效,则返回-1
- 另请参见:
-
convertYToRow(int),convertRowToY(int),updateLayoutState()
-
convertYToRow
protected int convertYToRow(int y0)
根据当前布局,将JList相对坐标转换为包含它的行。 如果y0不在任何行内,则返回-1。- 参数
-
y0- 相对Y坐标 - 结果
- 包含y0或-1的行
- 另请参见:
-
getRowHeight(int),updateLayoutState()
-
convertRowToY
protected int convertRowToY(int row)
返回指定行原点的JList相对Y坐标,如果行无效,则返回-1。- 参数
-
row- 一排 - 结果
- 行的原点的Y坐标,或-1
- 另请参见:
-
getRowHeight(int),updateLayoutState()
-
maybeUpdateLayoutState
protected void maybeUpdateLayoutState()
如果updateLayoutStateNeeded不为零,则调用updateLayoutState()并重置updateLayoutStateNeeded。 在根据列表的几何进行任何计算之前,应该通过方法调用此方法。 例如,它是paint()和getPreferredSize()中的第一个调用。- 另请参见:
-
updateLayoutState()
-
updateLayoutState
protected void updateLayoutState()
根据当前字体以及fixedCellWidth,fixedCellHeight和prototypeCellValue的当前值,重新计算cellHeight或cellHeights和cellWidth的值。- 另请参见:
-
maybeUpdateLayoutState()
-
createMouseInputListener
protected MouseInputListener 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) { // do some extra work when the mouse moves super.mouseMoved(e); } } }- 结果
-
MouseInputListener一个实例 - 另请参见:
-
BasicListUI.MouseInputHandler,installUI(javax.swing.JComponent)
-
createFocusListener
protected FocusListener createFocusListener()
返回FocusListener的实例。- 结果
-
FocusListener一个实例
-
createListSelectionListener
protected ListSelectionListener createListSelectionListener()
根据需要JLists由selectionModel添加到JLists的ListSelectionHandler的实例。 子类可以重写此方法以返回自定义ListSelectionListener,例如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); } } }- 结果
-
ListSelectionHandler的实例 - 另请参见:
-
BasicListUI.ListSelectionHandler,installUI(javax.swing.JComponent)
-
createListDataListener
protected ListDataListener createListDataListener()
创建一个ListDataListener的实例,根据需要按模型添加到JLists。 子类可以覆盖此方法以返回自定义ListDataListener,例如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); } } }- 结果
-
ListDataListener的实例 - 另请参见:
-
ListDataListener,JList.getModel(),installUI(javax.swing.JComponent)
-
createPropertyChangeListener
protected PropertyChangeListener createPropertyChangeListener()
创建的实例PropertyChangeHandler了加的JList由installUI()。 子类可以覆盖此方法以返回自定义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")) { // do some extra work when the model changes } super.propertyChange(e); } } }- 结果
-
PropertyChangeHandler的实例 - 另请参见:
-
PropertyChangeListener,installUI(javax.swing.JComponent)
-
-