Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dual Monitor Screenshots - One Blank



Hi all -

I'm trying to take screen shots using java.awt.Robot, but not having the best of luck on dual monitors setups. When I do so, the image from the second screen is all black.

I'm assuming this is a bug, but before I filed one, I figured I'd let you guys take a look to make sure I'm not doing anything silly.

Here's my test code:

-------------------------
public class ScreenshotTest {
	public static void main( String[] args ) throws Exception {
		GraphicsDevice[] devices =
			GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();

		BufferedImage[] images = new BufferedImage[ devices.length ];

		Robot robot = new Robot();
		for( int i = 0; i < devices.length; i++ ) {
			GraphicsDevice device = devices[ i ];

			GraphicsConfiguration config = device.getDefaultConfiguration();

			Rectangle bounds = config.getBounds();

			System.out.println( "Bounds for \"" + device.getIDstring() + "\": " +
				bounds );
			System.out.print( "  Attempting to capture screen..." );
			try {
				images[ i ] = robot.createScreenCapture( bounds );
				System.out.println( "successful." );
			}
			catch( Exception ex ) {
				System.out.println( "failed." );
				ex.printStackTrace();
			}
		}

		for( int i = 0; i < images.length; i++ ) {
			BufferedImage image = images[ i ];

			JFrame frame = new JFrame( "Image " + i );
			frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
			frame.getContentPane().add( new JScrollPane(
				new JLabel( new ImageIcon( image ) ) ) );
			frame.setSize( new Dimension( 500, 400 ) );
			frame.setVisible( true );
		}
	}
}
-------------------------

I get the same result with Java 5 and 6.

Thanks!

Rob

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.