Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8024184

Invalid rendering on JTable using DefaultTableCellRenderer

XMLWordPrintable

    • 2d
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version " 1.8.0-ea "
      Java(TM) SE Runtime Environment (build 1.8.0-ea-b102)
      Java HotSpot(TM) Server VM (build 25.0-b44, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Ubuntu 12.04 - 3.2.0-52-generic-pae

      A DESCRIPTION OF THE PROBLEM :
      I am using a default-cell-renderer for java.util.Date-columns on a JTable.
      Up to Java 7 that works as expected.
      With Java 8 the rendering is badly broken (on all available LookAndFeels).


      REGRESSION. Last worked in version 7u40

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile an run the testprogram.
      Scroll up and down the table-rows with keyboard and watch the columns drawings.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Normal rendering of the table-rows.
      ACTUAL -
      Broken rendering of the table-rows which use a DefaultCellRenderer.
      For example: wrong background-color, text of other cells is written over current cell, ...


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Component;
      import java.awt.EventQueue;
      import java.text.SimpleDateFormat;
      import java.util.Date;

      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import javax.swing.UIManager;
      import javax.swing.WindowConstants;
      import javax.swing.plaf.nimbus.NimbusLookAndFeel;
      import javax.swing.table.AbstractTableModel;
      import javax.swing.table.DefaultTableCellRenderer;

      public class TestTable
        implements Runnable {

        static class TM
          extends AbstractTableModel {
          static Class<?>[] clazzes = { Number.class, Date.class, String.class };

          @Override
          public int getColumnCount() {
            return clazzes.length;
          }

          @Override
          public Class<?> getColumnClass(final int columnIndex) {
            return clazzes[columnIndex];
          }

          @Override
          public String getColumnName(final int column) {
            return clazzes[column].getSimpleName();
          }

          @Override
          public int getRowCount() {
            return 5000;
          }

          @Override
          public Object getValueAt(final int rowIndex, final int columnIndex) {
            switch (columnIndex) {
              case 0:
                return Integer.valueOf(rowIndex);
              case 1:
                return new Date();
              case 2:
                return String.valueOf(rowIndex);
              default:
                break;
            }
            return null;
          }

        }

        JPanel p;
        JTable t;
        boolean doDateRenderer;

        public TestTable() {
          super();
          createComps();
        }

        protected void createComps() {
          try {
            // for (final LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels())
            // System.out.println(laf);
            // Metal javax.swing.plaf.metal.MetalLookAndFeel
            // Nimbus javax.swing.plaf.nimbus.NimbusLookAndFeel
            // CDE/Motif com.sun.java.swing.plaf.motif.MotifLookAndFeel
            // GTK+ com.sun.java.swing.plaf.gtk.GTKLookAndFeel
            // UIManager.setLookAndFeel(GTKLookAndFeel.class.getName());
            // UIManager.setLookAndFeel(MetalLookAndFeel.class.getName());
            // UIManager.setLookAndFeel(MotifLookAndFeel.class.getName());
            UIManager.setLookAndFeel(NimbusLookAndFeel.class.getName());
          } catch (final Exception e) {
            e.printStackTrace();
          }
          p = new JPanel(new BorderLayout());
          t = new JTable(new TM());
          doDateRenderer = true;
          if (doDateRenderer)
            t.setDefaultRenderer(Date.class, new DefaultTableCellRenderer() {
              final SimpleDateFormat sdf =
                new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );

              @Override
              public Component getTableCellRendererComponent(final JTable table,
                final Object value, final boolean isSelected, final boolean hasFocus,
                final int row, final int column) {
                return super.getTableCellRendererComponent(table, sdf.format(value),
                  isSelected, hasFocus, row, column);
              }
            });
          p.add(new JScrollPane(t), BorderLayout.CENTER);
        }

        @Override
        public void run() {
          final JFrame f = new JFrame( " Tabletest " );
          f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
          f.getContentPane().add(p);
          f.pack();
          f.setSize(800, 600);
          f.setVisible(true);
        }

        public static void main(final String[] args) {
          EventQueue.invokeLater(new TestTable());
        }
      }

      ---------- END SOURCE ----------

        1. XrenderOff.png
          39 kB
          Alexander Zvegintsev
        2. XrenderOn.png
          41 kB
          Alexander Zvegintsev

            azvegint Alexander Zvegintsev
            rcalnan Roger Calnan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: