JDK-6322270 : parent-less dialogs cannot be found, automation blocker
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P1
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux
  • CPU: generic,x86
  • Submitted: 2005-09-09
  • Updated: 2017-05-16
  • Resolved: 2005-11-12
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.
JDK 6
6 b61Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
This is a result for the big fixed here:
6300062 - JDialog need to support true parent-less mode

The parentless dialogs cannot be found using the public Java API's.  Automation
tools depend on Frame.getFrames to access the GUI component tree, hence all
automation tools will be broken because of this.

While researching I found CR# 4262946 from the distant past which predicted this
result would occur if ownerless windows were allowed.

We understand there is a private method in the Window class which will be
a good workaround.  It has been implemented in a GUI automation framework used
by the IEC team.  However, this isn't an acceptable solution because of two
reasons:
a) We'd be dependant on a private method remaining the same (unsafe)
b) there's all the GUI automation tools made by non-Sun teams which will have
been broken, and they're even less likely to use a private method.

What is probably needed is a method:
   Window.getWindows
akin to 
   Frame.getFrames


--------------------- Test case:

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

public class FindWindowUtil {

    private static int count = 1;
    
    public static void main(String args[]) throws Throwable {
        
        Runnable runnable = new Runnable() {
            public void run() {
                JDialog jNoParentDialog = new JDialog();
                jNoParentDialog.setTitle("Swing Dialog - No Parent");
                jNoParentDialog.setBounds(0, 120, 300, 30);
                jNoParentDialog.setVisible(true);
            }
        };
        EventQueue.invokeAndWait(runnable);
        
        try {
            Thread.sleep(1000);
        } catch (Throwable t) { }
        
        printWindows(null);
        System.exit(0);
    }
    
    private static void printWindows(Window[] child) {
        
        if(child == null) { 
            child = Frame.getFrames();
        }
        
        for(int i=0; i<child.length; i++) {
            if(child[i] instanceof Frame) {
                System.out.println(
                    "(" + count + ") Frame: \"" + ((Frame)child[i]).getTitle() + "\"");
                count++;
                printWindows(((Frame) child[i]).getOwnedWindows());
            } else if(child[i] instanceof Dialog) {
                System.out.println(
                    "(" + count + ") Dialog: \"" + ((Dialog)child[i]).getTitle() + "\"");
                count++;
                printWindows(((Dialog) child[i]).getOwnedWindows());
            } else {
                System.out.println(
                    "(" + count + ") Window: \"" + child[i] + "\"");
                count++;
            }
        }
    }
}

Comments
EVALUATION Such functionality can't be introduced without any new API. A new method in Window class is planned to be added similiar to Frame.getFrames().
13-09-2005