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

SwingUtilities.paintComponent should ignore heavyweight components

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.3.1
    • client-libs
    • None

      SwingUtilities.paintComponent() takes a Component argument, so it is possible (though a pretty bad idea) for a java program to pass a heavyweight Component to paintComponent(). This was in part the cause for bug 4321847. With Kestrel (post build Y i.e. including the fix for 4321847), the following code throws a NullPointerException. With 1.4, the Button is painted over with the Frame's background color.

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

      public class otherTests {

          public static void main(String argv[]) {
              Button comp = new Button("Some nonsense");
              Frame pn = new Frame();
              pn.add(comp);
              pn.setSize(200,100);
              pn.setVisible(true);

              Rectangle bounds = comp.getBounds();
              comp.getGraphics().create(bounds.x, bounds.y, bounds.width,
                                                      bounds.height).getClipBounds();

              SwingUtilities.paintComponent(comp.getGraphics(), comp, pn,
                           bounds.x, bounds.y, bounds.width, bounds.height);
              System.out.println("OKAY");
          }

      }

            svioletsunw Scott Violet (Inactive)
            xdengsunw Xianfa Deng (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: