diff --git a/test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java b/test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java
index 075137ff091a170afc694d2b23470aa3385adda9..3fa4b8345b12e9a897f322c1ac63daa17521d45c 100644
--- a/test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java
+++ b/test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java
@@ -85,28 +85,27 @@ public class TrayIconScalingTest {
             System.out.println("SystemTray is not supported");
             return;
         }
-        PassFailJFrame passFailJFrame = PassFailJFrame.builder()
-                .title("TrayIcon Test Instructions")
-                .instructions(INSTRUCTIONS)
-                .testTimeOut(8)
-                .rows(25)
-                .columns(70)
-                .screenCapture()
-                .build();
 
-        createAndShowGUI();
-        // does not have a test window,
-        // hence only the instruction frame is positioned
-        PassFailJFrame.positionTestWindow(null,
-                PassFailJFrame.Position.HORIZONTAL);
+        createAndShowTrayIcon();
+
         try {
-            passFailJFrame.awaitAndCheck();
+            PassFailJFrame.builder()
+                    .title("TrayIcon Test Instructions")
+                    .instructions(INSTRUCTIONS)
+                    .testTimeOut(8)
+                    .rows(25)
+                    .columns(70)
+                    .screenCapture()
+                    .build()
+                    .awaitAndCheck();
         } finally {
-            tray.remove(icon);
+            if (tray != null) {
+                tray.remove(icon);
+            }
         }
     }
 
-    private static void createAndShowGUI() {
+    private static void createAndShowTrayIcon() {
         ArrayList<Image> imageList = new ArrayList<>();
         for (int size = 16; size <= 48; size += 4) {
             imageList.add(createIcon(size));
@@ -120,7 +119,7 @@ public class TrayIconScalingTest {
         try {
             tray.add(icon);
         } catch (AWTException e) {
-            throw new RuntimeException("Error while adding icon to system tray");
+            throw new RuntimeException("Error while adding icon to system tray", e);
         }
     }