Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
关于Editor和Renderer的一点认识

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

在Sun的官方网站上对Editor和Renderer的解释是如下:
Renderer:
Instead, a single cell renderer is generally used to draw all of the cells that contain the same type of data. You can think of the renderer as a configurable ink stamp that the table uses to stamp appropriately formatted data onto each cell. When the user starts to edit a cell's data, a cell editor takes over the cell, controlling the cell's editing behavior.
个人理解就是对于不同的数据显示不同的格式,相当于在MVC中根据不同的Model选择不同的View,Renderer就是给你这个选择的权利。默认的几种数据的显示方式如下:
  • Boolean — rendered with a check box.
  • Number — rendered by a right-aligned label.
  • Double, Float — same as Number, but the object-to-text translation is performed by a NumberFormat (in the API reference documentation) instance (using the default number format for the current locale).
  • Date — rendered by a label, with the object-to-text translation performed by a DateFormat (in the API reference documentation) instance (using a short style for the date and time).
  • ImageIcon, Icon — rendered by a centered label.
  • Object — rendered by a label that displays the object's string value.
  • 如果你有特殊的数据,想有特殊的显示方式,可以自己设定Cell的Renderer如下:
    TableCellRenderer weirdRenderer = new WeirdRenderer();
    table = new JTable(...) {
        public TableCellRenderer getCellRenderer(int row, int column) {
            if ((row == 0) && (column == 0)) {
                return weirdRenderer;
            }
            // else...
            return super.getCellRenderer(row, column);
        }
    };
    Editor是用于编辑数据,但是Renderer是用于显示数据。
    关于Editor,和Renderer遵守相同的法则




    相关文章

    相关软件