11/*
2- * Copyright (c) 2013, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2013, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3737import java .awt .event .KeyEvent ;
3838import java .awt .event .MouseAdapter ;
3939import java .awt .event .MouseEvent ;
40+ import java .awt .image .BufferedImage ;
41+ import java .io .File ;
42+ import java .io .IOException ;
4043
44+ import javax .imageio .ImageIO ;
4145import javax .swing .AbstractAction ;
4246import javax .swing .JComboBox ;
4347import javax .swing .JFrame ;
@@ -337,11 +341,11 @@ public static void main(String[] args) throws Throwable {
337341 }
338342 }
339343
340- try {
341- // Use Robot to automate the test
342- Robot robot = new Robot ();
343- robot .setAutoDelay (50 );
344+ // Use Robot to automate the test
345+ Robot robot = new Robot ();
346+ robot .setAutoDelay (50 );
344347
348+ try {
345349 SwingUtilities .invokeAndWait (TaskbarPositionTest ::new );
346350
347351 robot .waitForIdle ();
@@ -442,6 +446,9 @@ public static void main(String[] args) throws Throwable {
442446 hidePopup (robot );
443447
444448 robot .waitForIdle ();
449+ } catch (Throwable t ) {
450+ saveScreenCapture (robot , screens );
451+ throw t ;
445452 } finally {
446453 SwingUtilities .invokeAndWait (() -> {
447454 if (frame != null ) {
@@ -450,4 +457,17 @@ public static void main(String[] args) throws Throwable {
450457 });
451458 }
452459 }
460+
461+ private static void saveScreenCapture (Robot robot , GraphicsDevice [] screens ) {
462+ for (int i = 0 ; i < screens .length ; i ++) {
463+ Rectangle bounds = screens [i ].getDefaultConfiguration ()
464+ .getBounds ();
465+ BufferedImage image = robot .createScreenCapture (bounds );
466+ try {
467+ ImageIO .write (image , "png" , new File ("Screenshot.png" ));
468+ } catch (IOException e ) {
469+ e .printStackTrace ();
470+ }
471+ }
472+ }
453473}
0 commit comments