JDK-4284610 : Regression :JOptionPane's owned by non-resizable JDialog's have wrong frame icon
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-10-25
  • Updated: 2003-05-09
  • Resolved: 2000-03-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.3.1 ladybirdFixed 1.4.0Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description

Name: skT88420			Date: 10/25/99


There's been a regression from 1.2.2 where JOptionPane dialogs
that are owned by a non-resizable JDialog will not have the
correct frame icon. In 1.2.2 the JOptionPane dialog would
inherit the correct frame icon regardless of whether the
JDialog was resizable or not. In 1.3beta this only happens
if the JDialog IS resizable.

The following testcase will demonstrate the bug. Before
running it you need to change the source file to specify
the location of an image file that can be used for the frame
icon. Alternatively you can just comment out the call to set
the frame icon and you'll end up using the default Java coffee
cup icon. Either way the bug can be seen. Here's the code:

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

public class IconBug extends JFrame {
    private static final Image APP_ICON =
        new ImageIcon("d:/java/wve/src/images/SineWave.gif").getImage();

    private static final String MSG1 =
        "<html><font size=-1>" +
        "The frame icon should be the same as<p>" +
        "the main app window icon";

    private static final String MSG2 =
        "<html><font size=-1>" +
        "What kind of frame icon does this window have?<p>" +
        "In <b>1.2.2</b> it is the same as the main app window icon,<p>" +
        "but in <b><font color=red>1.3beta</font></b> it's the default "+
        "<i>Windows waving flag</i> icon!";

    public static void main(String[] args) {
        new IconBug();
    }

    public IconBug() {

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        setIconImage(APP_ICON);

        final JDialog dlg1 = new JDialog(this, "A resizable JDialog", false);
        dlg1.setResizable(true);
        JButton b1 = new JButton("Click to open JOptionPane");
        b1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(dlg1, MSG1);
            }
        });
        dlg1.getContentPane().add(b1);
        dlg1.pack();
        dlg1.setLocation(200,200);

        final JDialog dlg2 = new JDialog(this, "A NON-resizable JDialog", false);
        dlg2.setResizable(false);
        JButton b2 = new JButton("Click to open JOptionPane");
        b2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(dlg2, MSG2);
            }
        });
        dlg2.getContentPane().add(b2);
        dlg2.pack();
        dlg2.setLocation(300,300);

        JButton b = new JButton("Click here open the JDialogs");
        b.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dlg1.setVisible(true);
                dlg2.setVisible(true);
            }
        });

        getContentPane().add(b);
        pack();
        setVisible(true);
    }
}
(Review ID: 96926) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: ladybird merlin FIXED IN: ladybird merlin-beta INTEGRATED IN: ladybird merlin-beta
14-06-2004

SUGGESTED FIX Name: rpC71689 Date: 03/15/2000 ascend the hierarchy in search for the first valid icon. If we found none, take the default Java coffee cup icon. ------- awt_Dialog.cpp ------- *************** *** 502,526 **** BOOL isResizable = ((GetStyle() & WS_THICKFRAME) != 0); if (isResizable) { // if we're resizable, use the owner's icon - HWND hWndOwner = ::GetWindow(GetHWnd(), GW_OWNER); ! HICON hBigIcon ! = (HICON)::SendMessage(hWndOwner, WM_GETICON, ICON_BIG, NULL); if (hBigIcon == NULL) { ! hBigIcon = (HICON)::GetClassLong(hWndOwner, GCL_HICON); } ! HICON hSmallIcon ! = (HICON)::SendMessage(hWndOwner, WM_GETICON, ICON_SMALL, NULL); if (hSmallIcon == NULL) { ! hSmallIcon = (HICON)::GetClassLong(hWndOwner, GCL_HICONSM); } if (hSmallIcon == NULL) { ! hSmallIcon = hBigIcon; } SendMessage(WM_SETICON, ICON_SMALL, (LPARAM)hSmallIcon); SendMessage(WM_SETICON, ICON_BIG, (LPARAM)hBigIcon); } else { // if we're not resizable remove the icon SendMessage(WM_SETICON, ICON_BIG, NULL); --- 502,555 ---- BOOL isResizable = ((GetStyle() & WS_THICKFRAME) != 0); if (isResizable) { // if we're resizable, use the owner's icon ! HWND hValidIconOwner = NULL; // Last Non-NULL owner of the icon ! HWND hIconOwner = GetHWnd(); // Owner of the icon ! ! HICON hBigIcon = NULL; ! HICON hSmallIcon = NULL; ! BOOL ContinueLooking = TRUE; ! ! do { ! // Try to get a valid icon from the current window ! if (hSmallIcon == NULL) { ! hSmallIcon = (HICON)::SendMessage(hIconOwner, WM_GETICON, ICON_SMALL, NULL); ! } if (hBigIcon == NULL) { ! hBigIcon = (HICON)::SendMessage(hIconOwner, WM_GETICON, ICON_BIG, NULL); } + if (hIconOwner != NULL) { + hValidIconOwner = hIconOwner; + } + // If the current window doesn't have a valid icon, ascend one level + hIconOwner = ::GetWindow(hIconOwner, GW_OWNER); ! if (hIconOwner == NULL) { ! // If we failed to get a valid icon from the parents, acquire ! // default Java Coffee Cup icon if (hSmallIcon == NULL) { ! hSmallIcon = (HICON)::GetClassLong(hValidIconOwner, GCL_HICONSM); } + if (hBigIcon == NULL) { + hBigIcon = (HICON)::GetClassLong(hValidIconOwner, GCL_HICON); + } + // If we failed to retrieve java coffee cup icon (This should + // never happen!), assign default window icon and exit the loop if (hSmallIcon == NULL) { ! hSmallIcon = (HICON)::LoadIcon(NULL, IDI_WINLOGO); ! ContinueLooking = FALSE; } + if (hBigIcon == NULL) { + hBigIcon = (HICON)::LoadIcon(NULL, IDI_WINLOGO); + ContinueLooking = FALSE; + } + } + } while ((hSmallIcon == NULL || hBigIcon == NULL) && ContinueLooking); + SendMessage(WM_SETICON, ICON_SMALL, (LPARAM)hSmallIcon); SendMessage(WM_SETICON, ICON_BIG, (LPARAM)hBigIcon); + } else { // if we're not resizable remove the icon SendMessage(WM_SETICON, ICON_BIG, NULL); ======================================================================
11-06-2004

EVALUATION I'm able to reproduce this bug on NT with the latest 1.3 build. However, this is not a Swing bug -- JDialog inherits the icon functionality from java.awt.Dialog. reassigning to awt. amy.fowler@Eng 1999-11-03 Name: rpC71689 Date: 03/15/2000 the old code didn't have proper means to ascend more than one step in the hierarchy of frames in search for the valid icon, so it simply took the nearest accessible icon. To my mind, the best way is to borrow an icon from the nearest of ascendants of our dialog which has it available. Also, it seems that the same problem may arise with the big icon which represents our task during the quick task switching (done by Alt+Tab on Win). Suggested fix eliminates both bugs. ====================================================================== This issue arose again. See 4779641 and 4788660. ###@###.### 2003-05-09
09-05-2003