jdk/src/java.desktop/share/classes/javax/swing/TablePrintable.java
changeset 43077 785bbcd9812a
parent 34397 86a74cb6c903
--- a/jdk/src/java.desktop/share/classes/javax/swing/TablePrintable.java	Thu Dec 22 12:17:56 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/javax/swing/TablePrintable.java	Thu Dec 22 18:30:27 2016 +0530
@@ -380,6 +380,12 @@
         // print the current section of the table
         g2d.translate(-clip.x, -clip.y);
         g2d.clip(clip);
+
+        // set a property so that BasicTableUI#paint can know JTable printMode
+        // is FIT_WIDTH since TablePrintable.printMode is not accessible from BasicTableUI
+        if (printMode == JTable.PrintMode.FIT_WIDTH) {
+            table.putClientProperty("Table.printMode", JTable.PrintMode.FIT_WIDTH);
+        }
         table.print(g2d);
 
         // restore the original transform and clip
@@ -407,8 +413,18 @@
         for(int visrow = rMin; visrow < rMax; visrow++) {
             rowHeight += table.getRowHeight(visrow);
         }
-        g2d.drawRect(0, 0, visibleBounds.width, hclip.height + rowHeight);
+        // If PrintMode is FIT_WIDTH, then draw rect for entire column width while
+        // printing irrespective of how many columns are visible in console
+        if (printMode == JTable.PrintMode.FIT_WIDTH) {
+            g2d.drawRect(0, 0, clip.width, hclip.height + rowHeight);
+        } else {
+            g2d.drawRect(0, 0, visibleBounds.width, hclip.height + rowHeight);
+        }
 
+        // clear the property
+        if (printMode == JTable.PrintMode.FIT_WIDTH) {
+            table.putClientProperty("Table.printMode", null);
+        }
         // dispose the graphics copy
         g2d.dispose();
 
@@ -534,5 +550,4 @@
         } while (clip.width + colWidth <= pw);
 
     }
-
 }