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

KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy) affects created components

    Details

    • Subcomponent:
    • Resolved In Build:
      b130
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Verified

      Description

      Call to

       java.awt.KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy defaultPolicy)

      affects already created components, though the spec says:

              /**
               * Note: this call doesn't affect already created components as they have
               * their policy initialized. Only new components will use this policy as
               * their default policy.
               **/

      Please see the following code sample:

      ----

      import java.awt.*;

      public class Test {

          public static void main(String[] args) {
              
              KeyboardFocusManager currentKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();
              FocusTraversalPolicy defaultFTP = currentKFM.getDefaultFocusTraversalPolicy();
              ContainerOrderFocusTraversalPolicy newFTP = new ContainerOrderFocusTraversalPolicy();

              Frame frame = new Frame();
              Window window = new Window(frame);

              /**
               * Note: this call doesn't affect already created components as they have
               * their policy initialized. Only new components will use this policy as
               * their default policy.
               **/
              currentKFM.setDefaultFocusTraversalPolicy(newFTP);
              FocusTraversalPolicy resultFTP = window.getFocusTraversalPolicy();
              if (!resultFTP.equals(defaultFTP)) {
                  System.out.println("Failure! FocusTraversalPolicy should not change");
              }
              
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dav Andrei Dmitriev (Inactive)
                Reporter:
                dbessono Dmitry Bessonov
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: