模块 java.desktop

类 CellRendererPane

所有已实现的接口:
ImageObserver , MenuContainer , Serializable , Accessible

public class CellRendererPane extends Container implements Accessible
此类插入在单元格渲染器和使用它们的组件之间。它的存在只是为了阻止 repaint() 和 invalidate() 方法,否则这些方法会在配置渲染器时向上传播树。它由 JTable、JTree 和 JList 的实现使用。例如,以下是在 JList 中绘制每一行的代码中如何使用 CellRendererPane:
  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 的组件不执行任何操作。

Warning: 此类的序列化对象将与未来的 Swing 版本不兼容。当前的序列化支持适用于运行相同版本 Swing 的应用程序之间的短期存储或 RMI。从 1.4 开始,对所有 JavaBeans 的长期存储的支持已添加到 java.beans 包中。请参阅 XMLEncoder

自从:
1.2
  • 字段详细信息

    • accessibleContext

      protected AccessibleContext  accessibleContext
      AccessibleContext 与此关联 CellRendererPan
  • 构造方法详细信息

    • CellRendererPane

      public CellRendererPane()
      构造一个 CellRendererPane 对象。
  • 方法详情

    • invalidate

      public void invalidate()
      重写以避免在配置单元格渲染器子项时向上传播无效树。
      重写:
      invalidate 在类 Container
      参见:
    • paint

      public void paint(Graphics  g)
      不应该被调用。
      重写:
      paint 在类 Container
      参数:
      g - 指定的图形窗口
      参见:
    • update

      public void update(Graphics  g)
      不应该被调用。
      重写:
      update 在类 Container
      参数:
      g - 指定的图形窗口
      参见:
    • addImpl

      protected void addImpl(Component  x, Object  constraints, int index)
      如果指定的组件已经是它的子组件,那么我们什么都不用做——堆叠顺序对单元格渲染器组件无关紧要(CellRendererPane 无论如何都不绘制)。
      重写:
      addImpl 在类 Container
      参数:
      x - 要添加的组件
      constraints - 表示此组件布局约束的对象
      index - 在容器列表中插入组件的位置,其中 -1 表示追加到末尾
      参见:
    • paintComponent

      public void paintComponent(Graphics  g, Component  c, Container  p, int x, int y, int w, int h, boolean shouldValidate)
      在图形对象 g 上绘制单元格渲染器组件 c。在绘制组件之前,它被重新设置为 this(如果有必要),它的边界被设置为 w,h 并且图形对象被(有效地)转换为 x,y。如果它是 JComponent,则双缓冲会暂时关闭。绘制组件后,它的边界将重置为 -w、-h、0、0,这样,如果它是最后一个绘制的渲染器组件,它就不会开始消耗输入。 Container p 是我们实际绘制的组件,通常它等于 this.getParent()。如果 shouldValidate 为真,组件 c 将在绘制之前进行验证。
      参数:
      g - 要绘制的 Graphics 对象
      c - Component 绘制
      p - 实际绘制的 Container 组件
      x - 指定绘制区域左侧的 int,以像素为单位,从图形上下文的左边缘开始测量
      y - 一个 int,指定要绘制的区域的顶部,以从图形上下文的顶部边缘向下测量的像素为单位
      w - 指定绘制区域宽度的整数,以像素为单位
      h - 指定绘制区域高度的整数,以像素为单位
      shouldValidate - 如果为真,组件 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 - 指定绘制区域宽度的整数,以像素为单位
      h - 指定绘制区域高度的整数,以像素为单位
    • paintComponent

      public void paintComponent(Graphics  g, Component  c, Container  p, Rectangle  r)
      调用 this.paintComponent(g, c, p, rx, ry, r.width, r.height) 其中 r 是输入 Rectangle 参数。
      参数:
      g - 要绘制的 Graphics 对象
      c - Component 绘制
      p - 实际绘制的 Container 组件
      r - 要绘制的 Rectangle
    • getAccessibleContext

      public AccessibleContext  getAccessibleContext()
      获取与此 CellRendererPane 关联的 AccessibleContext。对于 CellRendererPanes,AccessibleContext采用 AccessibleCellRendererPane 的形式。如有必要,将创建一个新的 AccessibleCellRendererPane 实例。
      指定者:
      getAccessibleContext 在接口 Accessible
      重写:
      getAccessibleContext 在类 Component
      返回:
      作为此 CellRendererPane 的 AccessibleContext 的 AccessibleCellRendererPane