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

JTable rows not repainted when deeply nested in a JScrollPane

XMLWordPrintable

    • b01
    • 11
    • x86_64
    • linux

      ADDITIONAL SYSTEM INFORMATION :
      Observed in Java 11 Mac/Linux. Works correctly in Java 8 Mac/Linux

      A DESCRIPTION OF THE PROBLEM :
      When a JTable is wrapped in at least two JPanels, then displayed in a JScrollPane, the rows of the table are not drawn when scrolling. The table can be forced to update by selecting rows or minimizing/restoring the window.

      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      (See attached test class)
      Add a JScrollPane to a JFrame. Set the viewportview to a be a JPanel (panel A). Add a JPanel (panel B) to panel A, then add a JTable to panel B. The JTable needs to have enough rows for the scroll bars to be active.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Successive table rows are drawn as the scroll pane is scrolled up and down.
      ACTUAL -
      Blank rows are drawn when scrolling with the touchpad. Rows are partially drawn when clicking and dragging the scroll bar.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;

      import javax.swing.BorderFactory;
      import javax.swing.BoxLayout;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import javax.swing.table.AbstractTableModel;

      public class Main {

      private static class SampleTableModel extends AbstractTableModel {
              public int getColumnCount() { return 10; }
              public int getRowCount() { return 10;}
              public Object getValueAt(int row, int col) { if (row ==-10 && col==0) throw new IllegalArgumentException(); return Integer.valueOf(row*col); }
          };

      public static void main(String[] argv) {
      JFrame frame = new JFrame("scrollpane test");
      frame.setSize(400, 300);

      JPanel tables = new JPanel();
      tables.setLayout(new BoxLayout(tables, BoxLayout.Y_AXIS));

      for (int i = 0; i < 10; i++) {
      JPanel p = new JPanel(new BorderLayout());
      p.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "title" + i));
      JTable table = new JTable(new SampleTableModel());
      tables.add(p);
      p.add(table);
      }

      JScrollPane sp = new JScrollPane(tables);
      frame.getContentPane().add(sp);
      frame.setVisible(true);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Only have one level of JPanel between the JScrollPane and JTable.

      FREQUENCY : always


        1. Capture.JPG
          Capture.JPG
          32 kB
        2. Capture1.JPG
          Capture1.JPG
          33 kB
        3. Main.java
          1 kB

            rmahajan Rajat Mahajan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: