public int getMaxComponentWidth ( ) { int maxWidth = 0 ; for ( int index = 0 ; ; index ++ ) { Component component = this . getComponent ( index ) ; if ( component == null ) break ; if ( component instanceof JTableHeader ) continue ; // Don't use this one if ( component instanceof JPanel ) { // Use the rightmost child for the width for ( int i = 0 ; i < ( ( JPanel ) component ) . getComponentCount ( ) ; i ++ ) { Component childComponent = ( ( JPanel ) component ) . getComponent ( i ) ; int farthestWidth = childComponent . getX ( ) + ( ( JPanel ) component ) . getComponent ( i ) . getWidth ( ) ; maxWidth = Math . max ( maxWidth , Math . min ( component . getWidth ( ) , farthestWidth ) ) ; } } else maxWidth = Math . max ( maxWidth , component . getWidth ( ) ) ; } return maxWidth ; }
Get the widest component . To calculate the scale .