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

AWT FileDialog does not inherit icon image from parent Frame

    Details

    • 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:
      b124
    • OS:
      windows_7

      Description

      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)


      Testcode:

      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();
                  frame.setIconImage(image);
                  frame.setVisible(true);
              });

              // 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);
                  dialog.setModal(false);
                  dialog.setVisible(true);
              });

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

              // 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(() -> {
                  dialog.dispose();
                  frame.dispose();
              });

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

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


        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: