java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.CellRendererPane
- 所有已实现的接口:
-
ImageObserver
,MenuContainer
,Serializable
,Accessible
此类被插入在单元格渲染器和使用它们的组件之间。它存在的目的是阻止当渲染器被配置时,否则会向上传播repaint()和invalidate()方法。它被JTable、JTree和JList的实现使用。例如,这里是如何在代码中使用CellRendererPane来绘制JList中的每一行的:
cellRendererPane = new CellRendererPane(); ... Component rendererComponent = renderer.getListCellRendererComponent(); renderer.configureListCellRenderer(dataModel.getElementAt(row), row); cellRendererPane.paintComponent(g, rendererComponent, this, x, y, w, h);
渲染器组件必须重写isShowing()并无条件返回true才能正常工作,因为对于isShowing为false的组件,Swing不会执行任何操作。
警告: 此类的序列化对象将不兼容未来的Swing版本。当前的序列化支持适用于短期存储或在运行相同版本Swing的应用程序之间的RMI。从1.4开始,已将所有JavaBeans的长期存储支持添加到java.beans
包中。请参阅XMLEncoder
。
- 自从:
- 1.2
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
此类实现了CellRendererPane
类的辅助功能。Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Modifier and TypeFieldDescriptionprotected AccessibleContext
与此CellRendererPan
关联的AccessibleContext
Fields declared in class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
如果指定的组件已经是此类的子级,则我们不需要执行任何操作 - 对于单元格渲染器组件,堆叠顺序并不重要(CellRendererPane不会绘制)。获取与此CellRendererPane关联的AccessibleContext。void
覆盖以避免在配置单元格渲染器子级时向上传播invalidate。void
不应该被调用。void
paintComponent
(Graphics g, Component c, Container p, int x, int y, int w, int h) 调用this.paintComponent(g, c, p, x, y, w, h, false)。void
paintComponent
(Graphics g, Component c, Container p, int x, int y, int w, int h, boolean shouldValidate) 在图形对象g上绘制单元格渲染器组件c。void
paintComponent
(Graphics g, Component c, Container p, Rectangle r) 调用this.paintComponent(g, c, p, r.x, r.y, r.width, r.height),其中r
是输入的Rectangle
参数。void
不应该被调用。Methods declared in class java.awt.Container
add, add, add, add, add, addContainerListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, isValidateRoot, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, validate, validateTree
Methods declared in class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
accessibleContext
与此CellRendererPan
关联的AccessibleContext
-
-
Constructor Details
-
CellRendererPane
public CellRendererPane()构造一个CellRendererPane对象。
-
-
Method Details
-
invalidate
public void invalidate()覆盖以避免在配置单元格渲染器子级时向上传播invalidate。- 覆盖:
-
invalidate
在类Container
- 参见:
-
paint
不应该被调用。 -
update
不应该被调用。 -
addImpl
如果指定的组件已经是此类的子级,则我们不需要执行任何操作 - 对于单元格渲染器组件,堆叠顺序并不重要(CellRendererPane不会绘制)。 -
paintComponent
public void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h, boolean shouldValidate) 在图形对象g上绘制单元格渲染器组件c。在绘制组件之前,如果需要,将其重新父级化为此类,将其边界设置为w,h,并且图形对象(实际上)被翻译为x,y。如果是JComponent,临时关闭双缓冲。绘制组件后,将其边界重置为-w, -h, 0, 0,以便如果它是最后一个绘制的渲染器组件,则不会开始消耗输入。容器p是我们实际绘制的组件,通常等于this.getParent()。如果shouldValidate为true,则在绘制之前将验证组件c。- 参数:
-
g
- 要绘制的Graphics
对象 -
c
- 要绘制的Component
-
p
- 实际绘制的Container
组件 -
x
- 以像素为单位从图形上下文的左边缘测量的绘制区域的左侧的int值 -
y
- 以像素为单位从图形上下文的顶部边缘向下测量的绘制区域的顶部的int值 -
w
- 以像素为单位的绘制区域的宽度的int值 -
h
- 以像素为单位的绘制区域的高度的int值 -
shouldValidate
- 如果为true,则在绘制之前将验证组件c
-
paintComponent
调用this.paintComponent(g, c, p, x, y, w, h, false)。- 参数:
-
g
- 要绘制的Graphics
对象 -
c
- 要绘制的Component
-
p
- 实际绘制的Container
组件 -
x
- 以像素为单位从图形上下文的左边缘测量的绘制区域的左侧的int值 -
y
- 以像素为单位从图形上下文的顶部边缘向下测量的绘制区域的顶部的int值 -
w
- 以像素为单位的绘制区域的宽度的int值 -
h
- 以像素为单位的绘制区域的高度的int值
-
paintComponent
调用this.paintComponent(g, c, p, r.x, r.y, r.width, r.height),其中r
是输入的Rectangle
参数。- 参数:
-
g
- 要绘制的Graphics
对象 -
c
- 要绘制的Component
-
p
- 实际绘制的Container
组件 -
r
- 要绘制的Rectangle
-
getAccessibleContext
获取与此CellRendererPane关联的AccessibleContext。对于CellRendererPanes,AccessibleContext采用AccessibleCellRendererPane的形式。如果需要,将创建一个新的AccessibleCellRendererPane实例。- 指定者:
-
getAccessibleContext
在接口Accessible
- 覆盖:
-
getAccessibleContext
在类Component
- 返回:
- 作为此CellRendererPane的AccessibleContext的AccessibleCellRendererPane
-