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

Heavyweight Component.print() doesn't print anything

    Details

    • Subcomponent:
    • Understanding:
      Fix Understood
    • CPU:
      generic
    • OS:
      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
      ======================================================================

        Activity

        Hide
        agerasimsunw Alexander Gerasimov (Inactive) added a comment -
        BT2:WORK AROUND



        Name: agR10216 Date: 02/22/2003



        Use printAll() instead of print().

        ###@###.### 2003-02-22
        ======================================================================
        Show
        agerasimsunw Alexander Gerasimov (Inactive) added a comment - BT2:WORK AROUND Name: agR10216 Date: 02/22/2003 Use printAll() instead of print(). ###@###.### 2003-02-22 ======================================================================
        Hide
        bino Bino George added a comment -
        BT2:EVALUATION

        The problem is that the Component implementation of print just calls paint. For
        HeavyWeight components other than Canvas, paint is a noop. However printAll checks to see if it is a heavyweight and if it is, it calls peer.print on the
        component. So that is why printAll works but not print.

        ###@###.### 2003-10-01
        Show
        bino Bino George added a comment - BT2:EVALUATION The problem is that the Component implementation of print just calls paint. For HeavyWeight components other than Canvas, paint is a noop. However printAll checks to see if it is a heavyweight and if it is, it calls peer.print on the component. So that is why printAll works but not print. ###@###.### 2003-10-01

          People

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

            Dates

            • Created:
              Updated:
              Imported:
              Indexed: