JDK-6524954 : Dialog button dn't gain focus when parent(frame) is minimized & maximized
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_10
  • CPU: sparc
  • Submitted: 2007-02-14
  • Updated: 2014-04-01
  • Resolved: 2014-04-01
Related Reports
Relates :  
Description
I have frame with a button which invokes a dialog(modaless). when the dialog is visible , the dialog which has the button has the focus. I minimize the frame, the dialog also get minimized. When i click on the iconified frame on the taskbar or system tray. The frame & dialog visible ( normal state), Now i would expect that dialog button should have the focus, but the frame button is having the focus. This works fine in jdk1.4.2 , jdk1.5.0 , jdk 6.0 & it even works fine in jdk 7.0 till b03 , but fails from jdk7.0 b04 onwards. So this is a regression. It even works fine in 6u1. 

Step to reproduce:
------------------
1) Run the below program.
2) Click on the  "ShowDialogButton" button in the frame( which is having the focus)you will see a dialog.
3) Observe that dialog button is having the focus.
5) Minimize the frame. Both frame & dialog will be minimized.
5) Click on the frame (iconified) on the taskbar or systemtray.
6) Frame & Dialog is visible. Observe that Frame button is having the focus. Actually dialog button should have the focus. 

import java.awt.*;
public class TestFocus {
    private Frame frame=null;
    private Dialog dialog=null;
    private Button showDialogButton=null , dialogButton=null;
    TestFocus( ) {
        frame = new Frame();
        frame.setLayout(new java.awt.FlowLayout());
        showDialogButton = new Button("ShowDialogButton");
        showDialogButton.addActionListener(new java.awt.event.ActionListener(){
            public void actionPerformed(java.awt.event.ActionEvent ae){
                dialog = new Dialog(frame , "Test focus Owner",false);
                dialog.setLayout(new java.awt.FlowLayout());
                dialog.add(dialogButton = new Button("DialogButton"));
                dialog.pack();
                dialog.setLocation(200,200);
                dialog.setVisible(true);
            }
        });
        frame.add(showDialogButton);
        frame.pack();
        frame.setVisible(true);
    }
    public static void main(String []args){
        new TestFocus();
    }
}

Comments
There is no specification on such behavior. Otherwise, please reopen this issue.
01-04-2014

EVALUATION The fix for 6480534 affected the logic we use on window mapping. From the XWindowPeer class: public void handleMapNotifyEvent(XEvent xev) { <skip> if (shouldFocusOnMapNotify()) { requestInitialFocus(); } Debugging the code below, isUnhiding == "false" for dialog but even if it were "true" frame still would take focus while restoring. private boolean shouldFocusOnMapNotify() { boolean res = false; if (isBeforeFirstMapNotify) { <skip> } else { res = isUnhiding; // Unhiding } res = res && isFocusableWindow() && // General focusability !isModalBlocked(); // Modality return res; } If we track every dialog (if even non-blocking one) and check the focus owner in shouldFocusOnMapNotify() prior to focusing the window well it may work. I looked on how native applications behave and seem they may do both ways: steal focus from child (gimp with its Toolbox) and leave it on a child (konqueror with its About dialog). I don't see reason to consider it as defect we have to fix but leave it opened.
27-01-2011

EVALUATION On windows-i586: -test fails with jdk5 -test fails with jdk6b105 -test fails with jdk6u23 -test fails with jdk7b126 On linux -test passes with jdk6b104 -test fails with jdk7b125 There were a fix for 6480534 (among others) which went into the jdk7b04 and potentially may have caused the regression.
26-01-2011

EVALUATION Reproduced on SunOS 10.
14-02-2007