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

parent-less dialogs cannot be found, automation blocker

XMLWordPrintable

    • b61
    • generic, x86
    • generic, linux
    • Verified

      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++;
                  }
              }
          }
      }

            art Artem Ananiev (Inactive)
            dherronsunw David Herron (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: