JDK-8235170 : JTable.repaint(Rectangle) does not work reliably
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 11.0.5
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-11-21
  • Updated: 2021-07-22
  • Resolved: 2021-07-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11
11-poolResolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
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



Comments
Reported with JDK 11.0.5, As per description, repainting a rectangle spanning more than a single row, parts of the affected rectangle just become blank instead of painting the actual content. The issue seems restricted to JDK 11.0.5 as it works fine with later versions JDK 12 and above (attached screenshots). To verify, run the attached test case with respective JDK versions. Result: ============ 8u231: OK 11.0.5: Fail 12: OK 13: OK 14 ea b25: OK
02-12-2019