code: public static ImagePanel showWindow(BufferedImage img, String title, boolean closeOnExit ) {
  		JFrame frame = new JFrame(title);
  
  		ImagePanel panel = new ImagePanel(img);
  		panel.setScaling(ScaleOptions.DOWN);
  
  		// If the window will be too large to be displayed on the monitor set the bounds to something that can be
  		// shown. The default behavior will just change one axis leaving it to have an awkward appearance
  		Rectangle monitorBounds = frame.getGraphicsConfiguration().getBounds();
  		if( monitorBounds.width < img.getWidth() || monitorBounds.height < img.getHeight()) {
  			double scale = Math.min(monitorBounds.width/(double)img.getWidth(),monitorBounds.height/(double)img.getHeight());
  			int width = (int)(scale*img.getWidth());
  			int height = (int)(scale*img.getHeight());
  			panel.setPreferredSize(new Dimension(width,height));
  		}
  
  		frame.add(panel, BorderLayout.CENTER);
  		frame.pack();
  		frame.setLocationByPlatform(true);
  		frame.setVisible(true);
  		if( closeOnExit )
  			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
  		return panel;
  	}
docs: Creates a window showing the specified image.