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

Heavyweight Component.print() doesn't print anything

    XMLWordPrintable

Details

    • Fix Understood
    • generic
    • generic

    Description



      Name: agR10216 Date: 02/22/2003


      I want to print some heavyweight Component that isn't a
      Container on a Graphics. I expect Component.print() to do
      this job as well as Component.printAll(). But a heavyweight
      Component's print() doesn't print anything. This is rather
      odd.

      The following test case demonstrates the problem.

      -----------------------------------------------------------
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.image.BufferedImage;

      public class PrintTest extends Frame {
          private Label label = new Label("click me!");
          private ImageCanvas canvas1 = new ImageCanvas();
          private ImageCanvas canvas2 = new ImageCanvas();

          public PrintTest() {
              setLayout(new GridLayout(0, 1));
              add(label);
              add(canvas1);
              add(canvas2);
              label.addMouseListener(new MouseAdapter() {
                  public void mouseClicked(MouseEvent event) {
                      BufferedImage image1 = new BufferedImage(
                              label.getWidth(), label.getHeight(),
                              BufferedImage.TYPE_INT_ARGB);
                      Graphics g1 = image1.createGraphics();
                      label.printAll(g1);
                      canvas1.setImage(image1);

                      BufferedImage image2 = new BufferedImage(
                              label.getWidth(), label.getHeight(),
                              BufferedImage.TYPE_INT_ARGB);
                      Graphics g2 = image2.createGraphics();
                      label.print(g2);
                      canvas2.setImage(image2);
                  }
              });
              setSize(200, 200);
              addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      dispose();
                  }
              });
              setVisible(true);
          }

          public static void main(String[] args) {
              new PrintTest();
          }
      }

      class ImageCanvas extends Canvas {
          private Image image;
          public void paint(Graphics g) {
              if (image != null) {
                  g.drawImage(image, 0, 0, this);
              } else {
                  g.drawString("no image", 30, 30);
              }
          }
          public void setImage(Image im) {
              image = im;
              repaint();
          }
      }
      -----------------------------------------------------------

      ###@###.### 2002-02-22
      ======================================================================

      Attachments

        Activity

          People

            art Artem Ananiev (Inactive)
            agerasimsunw Alexander Gerasimov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Imported:
              Indexed: