0 Replies Latest reply on Oct 11, 2012 12:49 PM by oais

    Problem with JTable after rendering some cells.


      My Swing application uses the Substance Look & Feel.
      One of the components is a JTable. I use the following DefaultTableCellRenderer to render some cells based on its value:

      The problem is that after the cell is rendered it loses the general Look & Feel of the application.

      For example :

      -No alternative row shadings.
      -No Focus Color.
      -The Selection color is the normal color with no effects of the Substance Look & Feel.

      Here is my code :
      public class CustomCellRenderer extends DefaultTableCellRenderer {
          DecimalFormat numberFormat = new DecimalFormat("#,###.##;(#,###.##)");
          public Component getTableCellRendererComponent(JTable jTable, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
              Component c = super.getTableCellRendererComponent(jTable, value, isSelected, hasFocus, row, column);
              if (c instanceof JLabel && value instanceof Number) {
                  JLabel label = (JLabel) c;
                  Number num = (Number) value;
                  String text = numberFormat.format(num);
                  label.setForeground(num.doubleValue() < 0 ? Color.RED : Color.BLACK);
              return c;
      And then in the JTable:
       setDefaultRenderer(BigDecimal.class,new CustomCellRenderer());
      How can I repaint the cells to use the Substance Look & Feel or for that matter to take the general Look & Feel of the JTable in which it resides.