Difficulties understanding the renderers mechanism of swing's JTable and JTree

后端 未结 3 637
清歌不尽
清歌不尽 2020-12-02 02:03

Often, when using JTable or JTree user writes and assign it is own specific cell renderer.

It is very common to inherit user\'s component

3条回答
  •  长情又很酷
    2020-12-02 02:29

    In adition to @JB's clear explication of how JTable and JTree use the flyweight pattern, note how both classes provide public methods getCellRenderer() and getCellEditor(). Examine these methods to see how JTable uses Class Literals as Runtime-Type Tokens to select a renderer or editor by class, if none is specified by column. Internally, JTable uses a Hashtable defaultRenderersByColumnClass for instance storage.

提交回复
热议问题