Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4480044
Votes 19
Synopsis JFrame.setIconImage() does not work is used after the frame is setVisible
Category java:classes_awt
Reported Against 1.3.1
Release Fixed
State 11-Closed, Not Reproducible, bug
Priority: 4-Low
Related Bugs
Submit Date 15-JUL-2001
Description


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) 
======================================================================
Posted Date : 2006-07-24 07:20:34.0
Work Around


Use setIconImage(image) before the frame is set visible for the 1st time.
======================================================================
Evaluation
This problem only occurs on Solaris, not Windows.
  xxxxx@xxxxx   2001-07-19
Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=13754
Posted Date : 2006-06-20 01:04:34.0

The bug cannot be reproduced with b85, though it's rarely reproducible with b84 (linux-i586/Gnome 2.10). 
It may be a thread race, but as far as there're no test that could definitely reproduce this issue the bug may be safely closed.
Posted Date : 2006-07-24 13:45:31.0
Comments
  
  Include a link with my name & email   

Submitted On 11-OCT-2001
salim.virani
This problem is ALSO SEEN on J2SE build 1.3.1-b24 on Linux. 
I am running Red Hat Linux version 7.1

A very dirty workaround of using setVisible(false) followed 
by setVisible(true) changes the icon .... but caused a bad 
flicker !!


Submitted On 03-OCT-2002
shulok
Confirmed on J2SE 1.4.0.02 on Linux as well.
Mandrake 9.0

This should be a simple fix...


Submitted On 30-MAY-2003
kaytrenaf
 Icon rose = new ImageIcon("rose.gif");
        label2 = new JLabel("Label with text and icon", rose, SwingConstants.LEFT);
        label2.setToolTipText("This is label 2");
        c.add(label2);

I am having a problem with JFrame displaying my image; I am getting the lable and the ToolTipText but not the image.


Submitted On 15-JUN-2003
clp3
Frame.setIconImage() works okay on visible frames 
on Windows 2000.

This does not update a visible frame's icon on Linux/KDE,
until you restart the KDE toolbar, or do:
    frame.hide();
    frame.show();



Submitted On 27-JUN-2003
ricky_clarkson
I'm not sure whether all taskbars, window switchers etc.
have an API for notification of change of icon, so, unless
Sun write code for each window manager, I can't imagine this
working properly.


Submitted On 27-JUN-2003
ricky_clarkson
Er, forget that last one.  It seems there are property
change events in X, so there is probably a general solution.


Submitted On 09-FEB-2004
vegala
I can't belive this bug is still open.  It should be a
simple fix.




PLEASE NOTE: JDK6 is formerly known as Project Mustang