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

REG: Printing AWT components through PrintJob throws an exception on linux

XMLWordPrintable

    • b55
    • x86
    • linux

      I am printing a frame having 2 checkboxes through AWT PrintJob by calling frame.printAll() and passing the graphics object obtained from PrintJob. When the checkboxes are selected, a ClassCastException is thrown on Linux for sun.print.PrintProxyGraphics. This occurs only when the checkboxes are selected. This is reproducible on Tiger-beta1-b32d and not reproducible on Tiger-beta-b09 and previous releases. Hence this is a regression introduced in Tiger-beta. This is not reproducible on Solaris9 and WinXP. I tested this with JDS-CINNABAR and Linux Redhat 9.

      When I looked into it more closely, In sun.awt.X11.XCheckboxPeer.paintCheckbox() method, at line no. 333, the graphics object given to the method has been downcasted to Graphics2D to get the affine transform. This will work fine for normal graphics objects but not for the graphics objects obtained from PrintJob since the ProxyPrintGraphics extends ProxyGraphics which inturn extends Graphics class. This is noticed for Scrollbar also. Inside sun.awt.X11.XScrollbar.paint(), the graphics object has been downcasted to Graphics2D object and that causes this exception.
       
      I have attached a test. Execute the testcase. You will find 2 checkboxes. Select the checkboxes. Choose any of the dialogs and click print. You will notice a ClassCastException in the console.

      Here is the exception:
      java.lang.ClassCastException: sun.print.ProxyPrintGraphics
      at sun.awt.X11.XCheckboxPeer.paintCheckbox(XCheckboxPeer.java:333)
      at sun.awt.X11.XCheckboxPeer.paint(XCheckboxPeer.java:308)
      at sun.awt.X11.XComponentPeer.print(XComponentPeer.java:519)
      at java.awt.GraphicsCallback$PeerPrintCallback.run(GraphicsCallback.java:85)
      at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
      at java.awt.Component.printAll(Component.java:2834)
      at sun.awt.SunGraphicsCallback$PrintHeavyweightComponentsCallback.run(SunGraphicsCallback.java:130)
      at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
      at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
      at sun.awt.X11.XPanelPeer.print(XPanelPeer.java:54)
      at java.awt.GraphicsCallback$PeerPrintCallback.run(GraphicsCallback.java:85)
      at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
      at java.awt.Component.printAll(Component.java:2834)
      at sun.awt.SunGraphicsCallback$PrintHeavyweightComponentsCallback.run(SunGraphicsCallback.java:130)
      at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
      at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
      at sun.awt.X11.XPanelPeer.print(XPanelPeer.java:54)
      at sun.awt.X11.XFramePeer.print(XFramePeer.java:475)
      at java.awt.GraphicsCallback$PeerPrintCallback.run(GraphicsCallback.java:85)
      at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
      at java.awt.Component.printAll(Component.java:2834)
      at PrintJobTest.actionPerformed(PrintJobTest.java:47)
      at java.awt.Button.processActionEvent(Button.java:388)
      at java.awt.Button.processEvent(Button.java:356)
      at java.awt.Component.dispatchEventImpl(Component.java:3931)
      at java.awt.Component.dispatchEvent(Component.java:3779)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

            art Artem Ananiev (Inactive)
            gramachasunw Girish Ramachandran (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: