Java Tips Weblog

Archive for the ‘Table’ Category

Vertical Table Header Cell Renderer

Posted by Darryl Burke on March 6, 2009

Does your JTable have short column content, but long column names? Do the column headers take up more horizontal space than you can spare?

No longer do you need to resort to cryptic two and three letter column headings in an attempt to solve this problem. Just rotate your table header text to the vertical, using VerticalTableHeaderCellRenderer.
Read the rest of this entry »

Posted in Extensions, Swing, Table | 9 Comments »

Default Table Header Cell Renderer

Posted by Darryl Burke on February 27, 2009

The javax.swing package and its subpackages provide a fairly comprehensive set of default renderer implementations, suitable for customization via inheritance. A notable omission is the lack of a default renderer for a JTableHeader in the public API. The renderer used by default is a Sun proprietary class, sun.swing.table.DefaultTableCellHeaderRenderer, which cannot be extended.

DefaultTableHeaderCellRenderer seeks to fill this void, by providing a rendering designed to be identical with that of the proprietary class, with one difference: the vertical alignment of the header text has been set to BOTTOM, to provide a better match between DefaultTableHeaderCellRenderer and other custom renderers.
Read the rest of this entry »

Posted in Extensions, Swing, Table | 6 Comments »

Icon Table Cell Renderer

Posted by Darryl Burke on December 18, 2008

The suplied default renderer for JTable columns of class Icon and ImageIcon, JTable.IconRenderer, is known to give rise to a ClassCastException when attempting to render an Icon whose implementation of paintIcon(…) requires a cast of its Component parameter to a specific subclass of Component. Several icons obtained from standard JDK classes trigger this ClassCastException.

IconTableCellRenderer addresses this issue by attempting to paint the Icon in 3 different ways before falling back on a default icon which can be customized via a parameter to the constructor.
Read the rest of this entry »

Posted in Extensions, Swing, Table | 7 Comments »