< prev index next >

src/java.desktop/share/classes/javax/swing/JTabbedPane.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 1997, 2024, 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
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

@@ -29,10 +29,11 @@
  import java.awt.Component;
  import java.awt.Cursor;
  import java.awt.Dimension;
  import java.awt.Font;
  import java.awt.FontMetrics;
+ import java.awt.IllegalComponentStateException;
  import java.awt.Point;
  import java.awt.Rectangle;
  import java.awt.event.FocusListener;
  import java.awt.event.MouseEvent;
  import java.beans.BeanProperty;

@@ -2335,19 +2336,27 @@
              Rectangle r = getBounds();
              return r.contains(p);
          }
  
          public Point getLocationOnScreen() {
-              Point parentLocation = parent.getLocationOnScreen();
+              Point parentLocation;
+              try {
+                  parentLocation = parent.getLocationOnScreen();
+              } catch (IllegalComponentStateException icse) {
+                  return null;
+              }
               Point componentLocation = getLocation();
+              if (parentLocation == null || componentLocation == null) {
+                  return null;
+              }
               componentLocation.translate(parentLocation.x, parentLocation.y);
               return componentLocation;
          }
  
          public Point getLocation() {
               Rectangle r = getBounds();
-              return new Point(r.x, r.y);
+              return r == null ? null : new Point(r.x, r.y);
          }
  
          public void setLocation(Point p) {
              // do nothing
          }

@@ -2360,11 +2369,11 @@
              // do nothing
          }
  
          public Dimension getSize() {
              Rectangle r = getBounds();
-             return new Dimension(r.width, r.height);
+             return r == null ? null : new Dimension(r.width, r.height);
          }
  
          public void setSize(Dimension d) {
              // do nothing
          }
< prev index next >