Class IconTableCellRenderer

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants, TableCellRenderer

    public class IconTableCellRenderer
    extends DefaultTableCellRenderer
    The package-private class javax.swing.JTable.IconRenderer, which is the default renderer for columns of class Icon and ImageIcon, is known to give rise to a ClassCastException when attempting to render an Icon whose implementation of paintIcon(Component c, Graphics g, int x, int y) requires a cast of its first parameter to a specific subclass of Component. Many icons obtained from standard JDK classes trigger this ClassCastException.

    IconTableCellRenderer addresses this issue in the following manner:

    • First, attempt to paint the Icon to the Graphics context of a BufferedImage with a reference to itself as the Component parameter.
    • In case of a ClassCastException, the desired class is identified by parsing the exception's message. An attempt is made to instantiate a Component of the desired class and use it as a valid reference.
    • In case of an InstantiationException, which is thrown if the desired class is abstract, a final attempt is made to draw the icon with a concretized AbstractButton as the Component parameter.
    • All else failing, the icon is rendered as a crossed rectangle of the same size as the original icon, or the default icon if supplied as a parameter to the constructor.
    • Extends DefaultTableCellRenderer

    Author:
    Darryl
    See Also:
    DefaultTableCellRenderer, Serialized Form