public static double selectZoomToFitInDisplay ( int width , int height ) { Dimension screenSize = Toolkit . getDefaultToolkit ( ) . getScreenSize ( ) ; double w = screenSize . getWidth ( ) ; double h = screenSize . getHeight ( ) ; double scale = Math . max ( width / w , height / h ) ; if ( scale > 1.0 ) { return 1.0 / scale ; } else { return 1.0 ; } }
Figures out what the scale should be to fit the window inside the default display