< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableUI.java

Print this page

        

@@ -1810,13 +1810,15 @@
             return;
         }
 
         boolean ltr = table.getComponentOrientation().isLeftToRight();
 
-        Point upperLeft = clip.getLocation();
-        Point lowerRight = new Point(clip.x + clip.width - 1,
-                                     clip.y + clip.height - 1);
+        // compute the visible part of table which needs to be painted 
+        Rectangle visibleBounds = clip.intersection(bounds);
+        Point upperLeft = visibleBounds.getLocation();
+        Point lowerRight = new Point(visibleBounds.x + visibleBounds.width - 1,
+                                     visibleBounds.y + visibleBounds.height - 1);
 
         int rMin = table.rowAtPoint(upperLeft);
         int rMax = table.rowAtPoint(lowerRight);
         // This should never happen (as long as our bounds intersect the clip,
         // which is why we bail above if that is the case).

@@ -1841,10 +1843,25 @@
         // Replace this with the index of the last column.
         if (cMax == -1) {
             cMax = table.getColumnCount()-1;
         }
 
+        Container comp = SwingUtilities.getUnwrappedParent(table); 
+        if (comp != null) {
+            comp = comp.getParent();
+        }
+
+        if (comp != null && !(comp instanceof JViewport) && !(comp instanceof JScrollPane)) {
+            // We did rMax-1 to paint the same number of rows that are drawn on console
+            // otherwise 1 extra row is printed per page than that are displayed
+            // when there is no scrollPane and we do printing of table
+            // but not when rmax is already pointing to index of last row
+            if (rMax != (table.getRowCount() - 1)) {
+                rMax = rMax - 1;
+            }
+        }
+
         // Paint the grid.
         paintGrid(g, rMin, rMax, cMin, cMax);
 
         // Paint the cells.
         paintCells(g, rMin, rMax, cMin, cMax);
< prev index next >