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

setFocusTraversalPolicy() to ContainerOrderFocusTraversalPolicy results in an infinite loop

XMLWordPrintable

    • b110
    • generic
    • generic

      The attached java program creates a Panel and adds 2 Buttons to it.

      Then it creates a new FocusTraversalPolicy ftp = new ContainerOrderFocusTraversalPolicy() and sets it as the focus traversal policy for the panel using panel.setFocusTraversalPolicy(ftp).

      Then it uses FTP's getFirstComponent(), getComponentAfter() to iterate through the panel's children by the order of the focus traversal.

      During that cycle we expect to get, first, Button1, then, Button2 because the Javadoc says:
      "From a particular focus cycle root, the policy makes a pre-order traversal of the Component hierarchy, and traverses a Container's children according to the ordering of the array returned by Container.getComponents()."
      and because getComponents() returns Button1 and Button2 only.

      However, we see that the loop never terminates constantly returning the Panel itself.

      If, however, we do not invoke setFocusTraversalPolicy on the Panel and use the default focus traversal policy that comes with the panel then the loop does terminate returning the Panel itself, Button1 and Button2.
      This behavior, however, seems also not in accordance to Javadoc as only Buton1 and Button2 would be expected.

      This CR relates to JDK-4959482. However, the explanation given in JDK-4959482 seems not to be sufficient. We did replace JApplet in the initial test by the Panel as was advised in JDK-4959482 and yet we see the same behaviour.

            arapte Ambarish Rapte
            mkhramov Maksim Khramov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: