diff --git a/test/jdk/javax/swing/JComponent/7154030/bug7154030.java b/test/jdk/javax/swing/JComponent/7154030/bug7154030.java
index 4835c07bf94f1..4856671727601 100644
--- a/test/jdk/javax/swing/JComponent/7154030/bug7154030.java
+++ b/test/jdk/javax/swing/JComponent/7154030/bug7154030.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,14 +30,9 @@
 import javax.swing.JFrame;
 import javax.swing.SwingUtilities;
 
-import java.awt.AWTException;
-import java.awt.AlphaComposite;
 import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
+import java.awt.Insets;
 import java.awt.Rectangle;
-import java.awt.Robot;
-import java.awt.Toolkit;
 import java.awt.image.BufferedImage;
 import javax.imageio.ImageIO;
 import java.io.File;
@@ -98,10 +93,11 @@ public void run() {
             robot.waitForIdle(1000);
 
             Rectangle bounds = frame.getBounds();
-            locx = bounds.x;
-            locy = bounds.y;
-            frw = bounds.width;
-            frh = bounds.height;
+            Insets insets = frame.getInsets();
+            locx = bounds.x + insets.left;
+            locy = bounds.y + insets.top;
+            frw = bounds.width - insets.left - insets.right;
+            frh = bounds.height - insets.top - insets.bottom;
 
             imageInit = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));