- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.CellRendererPane
-
- All Implemented Interfaces:
-
ImageObserver
,MenuContainer
,Serializable
,Accessible
public class CellRendererPane extends Container implements Accessible
此类插入到单元格渲染器和使用它们的组件之间。 它只是阻止重绘()和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以正常工作,因为Swing绘图对于具有isShowing false的组件不起作用。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,支持所有JavaBeans的长期存储已被添加到
java.beans
包中。 请参阅XMLEncoder
。- 从以下版本开始:
- 1.2
- 另请参见:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 描述 protected class
CellRendererPane.AccessibleCellRendererPane
该类为CellRendererPane
类实现可访问性支持。-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
-
Field Summary
Fields Modifier and Type Field 描述 protected AccessibleContext
accessibleContext
AccessibleContext
与此CellRendererPan
相关联-
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
构造方法摘要
构造方法 Constructor 描述 CellRendererPane()
构造一个CellRendererPane对象。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 protected void
addImpl(Component x, Object constraints, int index)
如果指定的组件已经是一个小孩,那么我们不用担心任何事情 - 堆栈顺序对于单元格渲染器组件并不重要(CellRendererPane不会绘制)。AccessibleContext
getAccessibleContext()
获取与此CellRendererPane关联的AccessibleContext。void
invalidate()
当配置单元格渲染器子时,覆盖以避免传播使树无效。void
paint(Graphics g)
不应该叫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)
在图形对象上绘制单元格渲染器组件c。void
paintComponent(Graphics g, Component c, Container p, Rectangle r)
调用this.paintComponent()与矩形x,y,width,height字段。void
update(Graphics g)
不应该叫-
Methods inherited from 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
-
Methods inherited from 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
-
-
-
-
字段详细信息
-
accessibleContext
protected AccessibleContext accessibleContext
AccessibleContext
与此CellRendererPan
相关联
-
-
方法详细信息
-
invalidate
public void invalidate()
当配置单元格渲染器子时,覆盖以避免传播使树无效。- 重写:
-
invalidate
在Container
- 另请参见:
-
Container.validate()
,Container.layout()
,LayoutManager2
-
paint
public void paint(Graphics g)
不应该叫- 重写:
-
paint
在Container
- 参数
-
g
- 指定的图形窗口 - 另请参见:
-
Component.update(Graphics)
-
update
public void update(Graphics g)
不应该叫- 重写:
-
update
在Container
- 参数
-
g
- 指定的图形窗口 - 另请参见:
-
Component.update(Graphics)
-
addImpl
protected void addImpl(Component x, Object constraints, int index)
如果指定的组件已经是一个小孩,那么我们不用担心任何事情 - 堆栈顺序对于单元格渲染器组件并不重要(CellRendererPane不会绘制)。- 重写:
-
addImpl
在Container
- 参数
-
x
- 要添加的组件 -
constraints
- 表示该组件的布局约束的对象 -
index
- 容器列表中插入组件的位置,其中-1
表示附加到最后 - 另请参见:
-
Container.add(Component)
,Container.add(Component, int)
,Container.add(Component, java.lang.Object)
,Container.invalidate()
,LayoutManager
,LayoutManager2
-
paintComponent
public void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h, boolean shouldValidate)
在图形对象上绘制单元格渲染器组件c。 在组件被绘制之前,它被重新定位到这个(如果需要的话),它的边界被设置为w,h,并且图形对象被有效地翻译成x,y。 如果它是一个JComponent,双缓冲暂时关闭。 在组件被绘制之后,它的边界被重置为-w,-h,0,0,这样,如果它是最后一个渲染器组件,则不会开始消耗输入。 容器p是我们实际绘制的组件,通常它等于this.getParent()。 如果shouldValidate为真,组件c将在绘制前验证。- 参数
-
g
- 要绘制的Graphics
对象 -
c
- 绘制Component
-
p
- 实际绘制的Container
组件 -
x
- 一个int指定从图形上下文的左边缘测量的区域的左侧,以像素为单位 -
y
- 一个int指定要绘制的区域的顶部,以从图形上下文的顶部边缘向下测量的像素 -
w
- 一个int指定绘制的区域的宽度,以像素为单位 -
h
- 一个int指定绘制的区域的高度,以像素为单位 -
shouldValidate
- 如果为true,组件c
将在绘制前进行验证
-
paintComponent
public 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)。- 参数
-
g
- 要绘制的Graphics
对象 -
c
- 绘制Component
-
p
- 实际绘制的Container
组件 -
x
- 指定绘制区域左侧的int(以像素为单位),从图形上下文的左边缘测量 -
y
- 一个int指定要绘制的区域的顶部,以从图形上下文的顶部边缘测量的像素 -
w
- 一个int指定绘制的区域的宽度,以像素为单位 -
h
- 一个int指定绘制的区域的高度,以像素为单位
-
paintComponent
public void paintComponent(Graphics g, Component c, Container p, Rectangle r)
调用this.paintComponent()与矩形x,y,width,height字段。- 参数
-
g
- 要绘制的Graphics
对象 -
c
- 绘制Component
-
p
- 实际绘制的Container
组件 -
r
- 要绘制的Rectangle
-
getAccessibleContext
public AccessibleContext getAccessibleContext()
获取与此CellRendererPane关联的AccessibleContext。 对于CellRendererPanes,AccessibleContext采用AccessibleCellRendererPane的形式。 如有必要,将创建一个新的AccessibleCellRendererPane实例。- Specified by:
-
getAccessibleContext
在接口Accessible
- 重写:
-
getAccessibleContext
在Component
- 结果
- 一个AccessibleCellRendererPane作为该CellRendererPane的AccessibleContext
-
-