RFR: 8210807: Printing a JTable with a JScrollPane prints table without rows populated [v3]

Prasanta Sadhukhan psadhukhan at openjdk.org
Wed Nov 8 13:36:03 UTC 2023


On Wed, 8 Nov 2023 10:29:15 GMT, Tejesh R <tr at openjdk.org> wrote:

>> `BackingStore` uses its own Graphics to Paint the Image. This is fine when we want to paint it on a Window/Frame, but fails to print. Since `WPathGraphics` is used for Printing, backing store fails to print it and backing store uses newly created `SunGraphics2D` always. The proposed fix is to ignore `backingstore` graphics if passed on Graphics is different from `SunGraphics2D` which ensures the Image is painted on Window and also printed when required. 
>> The fix is tested in CI and doesn't cause any regression. The test is verified manually.
>
> Tejesh R has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Review fix

src/java.desktop/share/classes/javax/swing/JViewport.java line 607:

> 605: 
> 606:     private Graphics getBackingStoreGraphics(Graphics g) {
> 607:         if (g instanceof SunGraphics2D) {

One thing is the change is not obvious as to why it is being done.
I think we can make the fix more telling by utilizing isPrinting check to make it prominent that the code path is for printing
Suggestion:

       if (!SwingUtilities2.isPrinting(g)) {

Can you see if it works? And yes, you have to make the method public..

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16552#discussion_r1386628386


More information about the client-libs-dev mailing list