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

Focus req across windows is expected to be denied on system not supporting cross win focus transfer

XMLWordPrintable

    • x86
    • solaris

      The spec
      http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/FocusSpec.html#RequestingFocus

      Says:
      "The request will also be denied if the Component's top-level Window is not the focused Window and the platform does not support requesting focus across Windows."

      This assertion is not satisfied on Solaris (not supporting cross window focus transfer) and JDK6 reference implementation.
      The following JCK tests (imported from PP TCK) fail due to this:

      api/java_awt/awt_focus_subsystem/requesting_focus/index.html#RequestFocus[RequestFocus_hw_0004]
      api/java_awt/awt_focus_subsystem/requesting_focus/index.html#RequestFocus[RequestFocus_lw_0004]
      JCK: 7b08
      JDK: 6b105
      Platform: Solaris


      Please see the following minimized test
      (for simplicity delays were inserted instead of more complex verifications in the original test cases)

      ---
      import java.awt.*;
      import java.awt.event.FocusListener;
      import java.awt.event.FocusEvent;

      public class CrossWindowFocusTransferBug {

          /**
           * Precondition: two components are in different frames:
           * firstFrame and secondFrame. secondComponent in secondFrame is the current focus owner.
           * <p/>
           * The test expects:
           * - firstComponent's request will be denied if the platform does not support
           * requesting focus across window
           */
          public static void main(String[] args) throws InterruptedException {

              Frame secondFrame = new Frame();
              Component firstComp = new Button();
              Component secondComp = new TextField();

              Frame firstFrame;
              firstFrame = new Frame();
              firstFrame.setLayout(new FlowLayout());
              firstFrame.setLocation(50, 50);
              firstFrame.setVisible(true);
              Thread.sleep(1000);
              firstFrame.add(firstComp);

              //focus the second frame

              secondFrame.setVisible(true);
              secondFrame.toFront();
              Thread.sleep(1000);
              System.out.println("second frame has focus: " + secondFrame.hasFocus());
              System.out.println("first frame has focus: " + firstFrame.hasFocus());

              secondComp.addFocusListener(new FocusListener() {
                  public void focusGained(FocusEvent e) {
                      System.out.println("second component gained the focus. It's OK");
                  }

                  public void focusLost(FocusEvent e) {
                  }
              });

              secondFrame.add(secondComp);
              System.out.println("requesting focus for the second component...");
              secondComp.requestFocus();
              Thread.sleep(1000);

              //start tracking the other component in another window
              firstComp.addFocusListener(new FocusListener() {
                  public void focusGained(FocusEvent e) {
                      System.out.println("first component gained the focus" +
                              " when its top-level window is not the " +
                              "focused window and platform does not " +
                              "support requesting focus across window. It's NOT OK");
                  }

                  public void focusLost(FocusEvent e) {
                  }
              });
              System.out.println("requesting focus for the first component...");
              firstComp.requestFocus();
              Thread.sleep(2000);

              firstFrame.dispose();
              secondFrame.dispose();

          }

      }
      ---

            Unassigned Unassigned
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: