< prev index next >

src/java.desktop/share/classes/java/awt/Component.java

Print this page

        

@@ -9737,23 +9737,31 @@
      *
      * @return the index of this object in its accessible parent
      */
     int getAccessibleIndexInParent() {
         synchronized (getTreeLock()) {
-            int index = -1;
-            Container parent = this.getParent();
-            if (parent != null && parent instanceof Accessible) {
-                Component ca[] = parent.getComponents();
-                for (int i = 0; i < ca.length; i++) {
-                    if (ca[i] instanceof Accessible) {
-                        index++;
+            if (!(this instanceof Accessible)) {
+                return -1;
                     }
-                    if (this.equals(ca[i])) {
-                        return index;
+
+            AccessibleContext accContext = getAccessibleContext();
+            if (accContext == null) {
+                return -1;
                     }
+
+            Accessible parent = accContext.getAccessibleParent();
+            if (parent == null) {
+                return -1;
+            }
+
+            accContext = parent.getAccessibleContext();
+            for (int i = 0; i < accContext.getAccessibleChildrenCount(); i++) {
+                if (this.equals(accContext.getAccessibleChild(i))) {
+                    return i;
                 }
             }
+
             return -1;
         }
     }
 
     /**
< prev index next >