private JTable withColRenderers ( final JTable table ) { // Data renderers final DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer ( ) ; // BigDecimal table . setDefaultRenderer ( BigDecimal . class , new TableCellRenderer ( ) { public Component getTableCellRendererComponent ( final JTable table , final Object value , final boolean isSelected , final boolean hasFocus , final int row , final int column ) { final BigDecimal bd = ( BigDecimal ) value ; return dtcr . getTableCellRendererComponent ( table , bd . toString ( ) , isSelected , hasFocus , row , column ) ; } } ) ; // Boolean table . setDefaultRenderer ( Boolean . class , new TableCellRenderer ( ) { public Component getTableCellRendererComponent ( final JTable table , final Object value , final boolean isSelected , final boolean hasFocus , final int row , final int column ) { final Boolean b = ( Boolean ) value ; return dtcr . getTableCellRendererComponent ( table , Boolean . toString ( b ) , isSelected , hasFocus , row , column ) ; } } ) ; // Date table . setDefaultRenderer ( java . sql . Date . class , new TableCellRenderer ( ) { public Component getTableCellRendererComponent ( final JTable table , final Object value , final boolean isSelected , final boolean hasFocus , final int row , final int column ) { final java . sql . Date d = ( java . sql . Date ) value ; return dtcr . getTableCellRendererComponent ( table , String . format ( "%tF" , d ) , isSelected , hasFocus , row , column ) ; } } ) ; // Time table . setDefaultRenderer ( Time . class , new TableCellRenderer ( ) { public Component getTableCellRendererComponent ( final JTable table , final Object value , final boolean isSelected , final boolean hasFocus , final int row , final int column ) { final Time t = ( Time ) value ; return dtcr . getTableCellRendererComponent ( table , String . format ( "%tr" , t ) , isSelected , hasFocus , row , column ) ; } } ) ; // Timestamp table . setDefaultRenderer ( Timestamp . class , new TableCellRenderer ( ) { public Component getTableCellRendererComponent ( final JTable table , final Object value , final boolean isSelected , final boolean hasFocus , final int row , final int column ) { final Time t = ( Time ) value ; return dtcr . getTableCellRendererComponent ( table , String . format ( "%tr" , t ) , isSelected , hasFocus , row , column ) ; } } ) ; return table ; }
Returns table with column renderers .