public int [ ] getComponentOrder ( Container container ) { int components = container . getComponentCount ( ) ; int [ ] componentOrder = new int [ components ] ; int [ ] rgY = new int [ components ] ; // First assume order is Y order for ( int i = 0 ; i < components ; i ++ ) { componentOrder [ i ] = i ; rgY [ i ] = container . getComponent ( i ) . getY ( ) ; } // Now bubble sort by Y for ( int i = 0 ; i < components ; i ++ ) { for ( int j = i + 1 ; j < components ; j ++ ) { if ( rgY [ j ] < rgY [ i ] ) { // Make component closer to top first int temp = rgY [ i ] ; rgY [ i ] = rgY [ j ] ; rgY [ j ] = temp ; temp = componentOrder [ i ] ; componentOrder [ i ] = componentOrder [ j ] ; componentOrder [ j ] = temp ; } } } return componentOrder ; }
Get the component order by how they are ordered vertically on the screen .