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

JTable.repaint(Rectangle) does not work reliably

    XMLWordPrintable

Details

    • 9
    • x86_64
    • windows_10

    Description

      A DESCRIPTION OF THE PROBLEM :
      When trying to repaint a rectangle spanning more than a single row, parts of the affected rectangle just become blank instead of painting the actual content.
      The bug seems to be introduced due to changes made to BasicTableUI by "8081491: The case print incomplete." and "8159068: The rendering of JTable is broken". The issue is partly fixed in Java 12 by "8202702: Clearing selection on JTable causes disappearance of a row" but only when the repainted rectangle does not intersect more than a single row.
      The issue does not occur if a row is selected or the parent component of the table is a JScrollPane or a JViewPort.

      REGRESSION : Last worked in version 8u231

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Simply call JTable.repaint(Rectangle) with a rectangle spanning more than one row

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The containing area of the rectangle is repainted completely
      ACTUAL -
      Parts of the rectangle are not repainted and are left blank, showing only the background color.

      ---------- BEGIN SOURCE ----------
        public static void main(String[] args) {
          JFrame frame = new JFrame();
          TableModel model = new DefaultTableModel(
              new String[][] { { "A0", "B0" }, { "A1", "B1" }, { "A2", "B2" }, { "A3", "B3" } },
              new String[] { "A", "B" });
          JTable table = new JTable(model);
          frame.add(table);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setSize(200, 200);
          frame.setVisible(true);
          SwingUtilities.invokeLater(() -> repaintRows(table));
        }

        private static void repaintRows(JTable table) {
          // get Rectangle for second row
          Rectangle r = table.getCellRect(1, 0, true);
          // expand cell rectangle to affect (parts of) third row
          r = new Rectangle(0, r.y, table.getWidth(), r.height * 2);
          table.repaint(r);
        }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Embedding the JTable into a JScrollPane or JViewPort. Alternatively simply repainting the whole table seems to work.

      FREQUENCY : always


      Attachments

        1. 11.0.5_capture.JPG
          11.0.5_capture.JPG
          13 kB
        2. 8u231_capture.JPG
          8u231_capture.JPG
          15 kB
        3. RepaintTest.java
          1 kB

        Issue Links

          Activity

            People

              psadhukhan Prasanta Sadhukhan
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: