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

AWT FileDialog does not inherit icon image from parent Frame


    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u92, 9
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
    • Environment:
    • Subcomponent:
    • Resolved In Build:
    • OS:


      On Windows 7 (may fail on other OS versions as well), the FileDialog should inherit the icon image from its parent, just like a regular AWT Dialog. It doesn't. Instead the standard Java icon is shown.

      This happens with JDK 8u92 and 9a118.

      The following test should pass on Windows 7, if FileDialog was implemented correctly. Currently it fails, because FileDialog is not working as expected and also, because SwingUtilities.convertPointToScreen(p, fileDialog) throws a NPE:

      Exception in thread "main" java.lang.NullPointerException: null pData
      at sun.awt.windows.WComponentPeer.getLocationOnScreen(Native Method)
      at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:2058)
      at java.awt.Component.getLocationOnScreen(Component.java:2036)
      at javax.swing.SwingUtilities.convertPointToScreen(SwingUtilities.java:381)


      import javax.swing.*;
      import java.awt.*;
      import java.awt.image.BufferedImage;
      import java.lang.reflect.InvocationTargetException;

      public class FileDialogIconTest {

          public static void main(final String[] args) throws InterruptedException, InvocationTargetException, AWTException {
              final Frame frame = new Frame();
              SwingUtilities.invokeLater(() -> {
                  final Image image = createImage();

              // when using:
              // final Dialog dialog = new Dialog(frame, "Dialog");
              // the test runs through with no problems.
              final Dialog dialog = new FileDialog(frame, "Dialog");
              SwingUtilities.invokeLater(() -> {
                  dialog.setBounds(100, 100, 100, 100);

              final Robot robot = new Robot();
              // give AWT some time to show the dialog

              // grab pixel from icon area - this is for Windows only!
              final Point p = new Point(10, 10);
              // currently this line fails with a NPE
              SwingUtilities.convertPointToScreen(p, dialog);
              final Color color = robot.getPixelColor(p.x, p.y);

              SwingUtilities.invokeAndWait(() -> {

              if (!Color.RED.equals(color)) {
                  throw new RuntimeException("Dialog icon was not inherited from owning window. Wrong color: " + color);

          private static Image createImage() {
              final BufferedImage image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
              final Graphics g = image.getGraphics();
              g.fillRect(0, 0, image.getWidth(), image.getHeight());
              return image;




            • Assignee:
              ssadetsky Semyon Sadetsky (Inactive)
              hschreiber Hendrik Schreiber
            • Votes:
              0 Vote for this issue
              4 Start watching this issue


              • Created: