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

Failure to print JTextPane under JDK 1.2.2

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.2
    • client-libs

      The following code works in 1.2, but does not print in 1.2.2:

      import java.util.*;
      import java.awt.*;
      import javax.swing.*;
      import javax.swing.text.*;

      class jtextbug {
         public static void main(String[] args) {
            try {
               JFrame frame = new JFrame();
               frame.setVisible(true); // else fails in LabelView:1315 -see Bug
      // #4239618
               PrintJob printjob = Toolkit.getDefaultToolkit().getPrintJob(
                  frame, "Job Title", new Properties());
               Graphics gc = printjob.getGraphics();
               gc.setClip(0, 0, 100, 100);

               DefaultStyledDocument doc = new DefaultStyledDocument();
               doc.insertString(0, "This is JDK 1.2.2", new SimpleAttributeSet());

               JTextPane text = new JTextPane(doc);
               text.setSize(100,100);
               frame.getContentPane().add(text);
               text.print(gc); // text.paint(gc) produces the same behaviour
            }
            catch (Throwable t) {
               t.printStackTrace();
            }
         }
      }

      When the OK button in the print dialog is clicked, a ClassCastException occurs:

      java.lang.ClassCastException: sun.awt.windows.WPrintGraphicsWrapper
              at
      javax.swing.text.LabelView$LabelFragment.paint(LabelView.java:761)
              at javax.swing.text.BoxView.paintChild(BoxView.java:102)
              at javax.swing.text.BoxView.paint(BoxView.java:287)
              at javax.swing.text.BoxView.paintChild(BoxView.java:102)
              at javax.swing.text.BoxView.paint(BoxView.java:287)
              at javax.swing.text.ParagraphView.paint(ParagraphView.java:657)
              at javax.swing.text.BoxView.paintChild(BoxView.java:102)
              at javax.swing.text.BoxView.paint(BoxView.java:287)
              at
      javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1048)
              at
      javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:426)
              at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:549)
              at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:528)
              at javax.swing.JComponent.paintComponent(JComponent.java:329)
              at javax.swing.JComponent.paint(JComponent.java:638)
              at java.awt.Component.print(Component.java:1957)
              at java.awt.Container.print(Container.java:813)
              at jtextbug.main(jtextbug.java:30)

      It appears that LabelView.LabelFragment.paint is attempting to cast a
      Graphics to a Graphics2D.

            tprinzing Tim Prinzing (Inactive)
            nrodinsunw Nick Rodin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: