Java Tips Weblog

  • Blog Stats

    • 2,530,127 hits
  • Categories

  • Archives

Archive for the ‘Table’ Category

Multisort Table Header Cell Renderer

Posted by Darryl Burke on August 29, 2010

It’s easy to make a JTable sortable by invoking setAutoCreateRowSorter(true). Clicking on the header of a column will then sort the rows on the basis of the contents of the cell in that column, and display an appropriate arrow icon. A little known fact is that the default, automatically created, RowSorter actually uses the last three sort indexes. Unfortunately, the only way the user can know which columns are involved in the subordinate sorting is by remembering the sequence in which the columns were clicked.

MultisortTableHeaderCellRenderer addresses this deficiency by showing the sort icons with decreasing opacity on all columns involved in the sort, making use of the AlphaIcon class published earlier.

Read the rest of this entry »


Posted in Classes, Extensions, Swing, Table | 4 Comments »

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 | 21 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 | 16 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 »