Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →To capture every monitor with Java’s Robot, calculate the union of all screen bounds and pass that virtual-desktop rectangle to createScreenCapture. Do not assume the desktop starts at (0, 0): a display arranged to the left of or above the primary monitor can have negative coordinates. For one monitor, use that display’s bounds instead. On a scaled display, consider createMultiResolutionScreenCapture and select the image variant that matches your output needs.
This works only in a graphical desktop session where Java can access the screen. It is not a way to screenshot a website from a headless server, and Robot screenshots do not include the mouse cursor.
Capture the entire virtual desktop
Robot captures the rectangle you give it; the default Robot() constructor does not, by itself, mean “capture every display.” Enumerate the graphics devices and their configurations, union their bounds, then use that union as the capture rectangle. This is the key to including monitors that extend beyond the primary screen.
The following program checks for a headless environment, computes the virtual desktop bounds, captures them, and writes a PNG:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
import java.awt.AWTException;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class CaptureDesktop {
public static void main(String[] args) throws IOException {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
if (ge.isHeadlessInstance()) {
throw new IllegalStateException("Screen capture requires a graphical environment.");
}
Rectangle virtualBounds = new Rectangle();
for (GraphicsDevice device : ge.getScreenDevices()) {
for (GraphicsConfiguration config : device.getConfigurations()) {
virtualBounds = virtualBounds.union(config.getBounds());
}
}
if (virtualBounds.width <= 0 || virtualBounds.height <= 0) {
throw new IllegalStateException("No usable screen bounds were found.");
}
try {
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(virtualBounds);
if (!ImageIO.write(image, "png", new File("desktop.png"))) {
throw new IOException("No PNG writer is available.");
}
System.out.println("Saved desktop.png: " + image.getWidth() + "x" + image.getHeight());
} catch (AWTException | SecurityException e) {
throw new IllegalStateException("Java could not access the desktop for capture.", e);
}
}
}
Save it as CaptureDesktop.java, compile with javac CaptureDesktop.java, and run it from the logged-in desktop session with java CaptureDesktop. The output file is written to the program’s current working directory. On a successful capture, the program prints the image dimensions; check those dimensions and open the PNG to confirm that every display and the intended arrangement are present.
Why use the union of bounds?
Each GraphicsConfiguration describes a display region in screen coordinates. Combining the rectangles gives the smallest rectangle that contains them all. Oracle’s API description calls this “the bounds of the virtual device.” The resulting rectangle can start at a negative X or Y coordinate. Those negative values are meaningful: they locate a monitor relative to the desktop coordinate origin. Do not clamp them to zero or replace them with a primary-screen width and height.
The union may contain unused space where monitors do not touch—for example, if one display is offset vertically. That gap is part of the bounding rectangle, so the captured image can include blank areas. This is expected; the union is a rectangle, not a stitched collage that removes empty space.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Inspect the layout before capturing
When a capture is missing a display, print the bounds that Java reports rather than guessing the coordinate arrangement. Add this diagnostic loop before calculating the union:
for (GraphicsDevice device : ge.getScreenDevices()) {
System.out.println("Device: " + device.getIDstring());
for (GraphicsConfiguration config : device.getConfigurations()) {
System.out.println(" Bounds: " + config.getBounds());
}
}
Use the runtime values to verify that every expected screen is represented and that left- or upper-positioned monitors have the coordinates you expect. The API allows systems to use a shared coordinate system for a combined virtual screen or separate coordinate systems for independent screens. Inspect actual bounds on the platform where the program runs; do not assume the same coordinate model everywhere.
Capture just one monitor
If the requirement is one display rather than the whole desktop, choose its GraphicsDevice, create a device-specific Robot, and capture a configuration’s bounds for that device. For example, this captures the default configuration of the first enumerated device:
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
if (ge.isHeadlessInstance()) {
throw new IllegalStateException("Screen capture requires a graphical environment.");
}
GraphicsDevice device = ge.getScreenDevices()[0];
Rectangle bounds = device.getDefaultConfiguration().getBounds();
try {
Robot robot = new Robot(device);
BufferedImage image = robot.createScreenCapture(bounds);
ImageIO.write(image, "png", new File("monitor.png"));
} catch (AWTException | SecurityException e) {
throw new IllegalStateException("Could not capture the selected display.", e);
}
For a particular non-default configuration, select that configuration from device.getConfigurations() and use its bounds. The array’s first device is not guaranteed by this example to be the monitor a user would call “primary”; use the device identifiers and bounds to make selection explicit for your application. If the platform exposes independent coordinate systems, a device-specific Robot is especially useful because it associates the Robot with the target graphics device.
Handle HiDPI and display scaling
On a high-resolution or scaled display, the size expressed in desktop coordinates may differ from the number of physical device pixels. If the distinction matters—for example, when preserving native-pixel detail—use createMultiResolutionScreenCapture(Rectangle) where available. It returns a MultiResolutionImage with a base user-size image and, when available, a native device-resolution variant. A non-scaled display may provide only one variant.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →import java.awt.GraphicsEnvironment;
import java.awt.GraphicsDevice;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.image.MultiResolutionImage;
import java.io.File;
import javax.imageio.ImageIO;
GraphicsDevice device = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();
Rectangle bounds = device.getDefaultConfiguration().getBounds();
Robot robot = new Robot(device);
MultiResolutionImage capture = robot.createMultiResolutionScreenCapture(bounds);
// Select the variant with the largest pixel area when native detail is preferred.
BufferedImage nativeVariant = capture.getResolutionVariants().stream()
.filter(BufferedImage.class::isInstance)
.map(BufferedImage.class::cast)
.max(java.util.Comparator.comparingLong(
image -> (long) image.getWidth() * image.getHeight()))
.orElseThrow(() -> new IllegalStateException("No buffered image variant found."));
ImageIO.write(nativeVariant, "png", new File("monitor-native.png"));
The selection above prefers the variant with the most pixels; it does not rescale the image. If downstream software expects logical desktop dimensions, use the base-size variant instead. Check the selected image’s width and height rather than assuming that a particular scale factor applies. Scaling behavior and available variants depend on the display and runtime environment.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
createMultiResolutionScreenCapture was added in Java 9. If you must support an earlier Java runtime, use createScreenCapture and verify the result on the actual scaled display; do not compile the multi-resolution example against an older API.
Errors, permissions, and limits
- Headless environment:
Robot()andRobot(GraphicsDevice)can throwAWTExceptionwhenGraphicsEnvironment.isHeadless()is true. A server process with no usable graphical desktop cannot capture a live screen this way. Check headless status before creating Robot and run the capture in an accessible desktop session. - Robot unavailable:
AWTExceptioncan also mean the platform cannot provide the low-level input control that Robot requires. Catch it and report that screen access is unavailable rather than treating it as a bad rectangle. - Screen-read permission denied:
createScreenCapturecan throwSecurityException. Some modern desktop environments may require explicit screen-recording approval. Grant the relevant permission to the application or runtime, then restart or retry as the operating system requires. - Invalid rectangle: A zero or negative capture width or height can cause
IllegalArgumentException. Log the computed bounds and validate that both dimensions are positive before capturing. - Cursor absent: Robot’s returned screen image excludes the mouse cursor. If the cursor must appear, Robot alone does not meet that requirement.
- Unexpected display missing: The capture rectangle may have been built from only the default screen or from assumed dimensions. Enumerate devices and configurations, inspect every bounds value, and rebuild the union.
- Unexpected output size: Scaling can produce a difference between desktop-coordinate dimensions and native pixels. Log the selected image dimensions and choose an appropriate multi-resolution variant when native detail is required.
- PNG write failure:
ImageIO.writereturnsfalseif no writer can encode the requested format. Check that return value, use a supported format, and verify that the destination directory is writable.
Keep capture work off the event-dispatch thread
A screen capture and image encoding can take long enough to make a desktop application feel unresponsive. Do not perform lengthy capture or file-writing work on Swing’s AWT event-dispatch thread. Trigger the operation in a background worker, then return to the UI thread only to update progress or display the result. For repeated captures, reuse the same validated bounds while the monitor layout remains unchanged; recompute them after display configuration changes so the rectangle does not become stale.
Large multi-monitor or native-resolution images use more memory than a single-monitor capture. Avoid retaining full-resolution images longer than needed, and consider capturing only the target device or region when the application does not need the whole desktop. A smaller rectangle also reduces the amount of image data that must be encoded and written.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Choose the capture method that matches the job
| Need | Approach | Important consideration |
|---|---|---|
| All connected displays in one image | Union every configuration’s bounds, then call createScreenCapture. |
The bounding rectangle may include empty space and can have a negative origin. |
| One display only | Create Robot(device) and capture that device’s configuration bounds. |
Identify the intended device from runtime IDs and bounds; do not assume array order means primary monitor. |
| Native-pixel detail on a scaled screen | Use createMultiResolutionScreenCapture and choose the resolution variant needed. |
Variant availability depends on the display; verify the resulting dimensions. |
| Headless server or website image | Robot is not suitable for a server without an accessible graphical desktop. Use a browser screenshot service for website capture. | A website screenshot is different from capturing the local desktop or arbitrary applications. |
Or skip the browser setup
If the job is a screenshot of a website rather than the local desktop, ScreenshotNeo provides a one-request API. It does not replace Robot for capturing monitors or other desktop applications. It removes cookie banners, newsletter popups, and chat widgets before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and 1,000 screenshots per month are free with no card; paid plans start at $5 for 3,000.
For example, capture a webpage as WebP with cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. Learn more at ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.
Frequently Asked Questions
Can Java Robot include the mouse pointer in a screenshot?
No. The image returned by Robot’s screen-capture API excludes the cursor.
Can I use Robot to capture a website on a headless server?
Not with Robot alone: it needs access to a graphical desktop. For a website screenshot rather than a local desktop capture, use a browser screenshot service.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

