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

JFrame.setIconImage() does not work is used after the frame is setVisible

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description

      Name: boT120536 Date: 07/15/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)


      If setIconImage(image) is called AFTER the frame is diplayed ( using show() or
      setVisible(true) ), the image is not displayed in the ICON box and the default
      image is used instead.

      Here is a demo:

      /*********************************************************/
      /*********************************************************/

      import java.awt.*;
      import javax.swing.*;
      import gov.nasa.ksc.clcs.utilx.SystemEnvironment;

      /**
       * This class will provides evidence that JFrame.setIconImage() will not
       * work if used after the frame has been shown (using JFrame.show() or
       * JFrame.setVisible().
       *
       * To duplicate the error just run the demo WITHOUT any command line options.
       * To duplicate a workaround, run the demo WITH a command line option.
       *
       * PS:
       * Bug was tested with 60x60 PNG, JPEG and GIF files. Solaris 2.6
       */

      public class TestIcons extends JFrame
      {
        public TestIcons(boolean showBefore)
        {
          super("TestIcon");
          super.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

          //Image icon = Toolkit.getDefaultToolkit().getImage( "./image.png" );
          Image icon = new ImageIcon( "./image.png" ).getImage();

          if( showBefore )
          {
            System.out.println("JFrame.setIconImage() ..... FAILED");
            super.show();
            super.setIconImage( icon );
          }
          else
          {
            System.out.println("JFrame.setIconImage() ..... WORKS");
            super.setIconImage( icon );
            super.show();
          }
        }
        
        
        public static void main(String[] args)
        {
          //If no commandline option is used. The error will be duplicated.
          //Otherwise, the working option is invoked.
          boolean bln = ( args.length == 0 );

          TestIcons f = new TestIcons(bln);

          // Iconifying frame to show the ICON. This is done since the
          // ICON will not be display in NORMAL state.
          f.setState( JFrame.ICONIFIED );
        }
        
      } // TestIcons
      /*********************************************************/
      (Review ID: 126410)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              anthony Anthony Petrov (Inactive)
              Reporter:
              bonealsunw Bret O'neal (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: