Rendering Odds and Ends

Both the JTree and JTable classes make use of cell renderers to display cells and cell editors to modify cell values. The following classes round out the utilities available for rendering information.

The CellRendererPane Class

This utility class was built to keep renderers from propagating repaint( ) and validate( ) calls to the components using renderer components such as JTree and JList. If you played around with creating your own renderers for any of the Swing components that use them, you’ll recall that you did not use this class yourself. Normally this pane is wrapped around the renderer and the various paintComponent( ) methods below are used to do the actual drawing. Developers do not normally need to worry about this class.

The Renderer Interface

The Swing package includes a Renderer interface (which does not appear to be used within Swing itself) with the following methods:

public Component getComponent( )

Return a Component you can use with something like the SwingUtilities.paintComponent( ) method to draw the value on the screen.

public void setValue(Object aValue, boolean isSelected)

This method can initialize the rendering component to reflect the state of the object aValue.

This interface could be useful if you were to create a library of renderers for use with your own applications; however, it is not implemented anywhere in the Swing package as of SDK 1.4.1.

The GrayFilter Class

The GrayFilter class is an extension of the java.awt.image.RGBImageFilter ...

Get Java Swing, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.