diff --git a/src/java.desktop/share/classes/javax/swing/ToolTipManager.java b/src/java.desktop/share/classes/javax/swing/ToolTipManager.java index 6b3619e8a7b..84d62e67c54 100644 --- a/src/java.desktop/share/classes/javax/swing/ToolTipManager.java +++ b/src/java.desktop/share/classes/javax/swing/ToolTipManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, 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 @@ -265,13 +265,19 @@ public final class ToolTipManager extends MouseAdapter implements MouseMotionLis toFind = new Point(screenLocation.x + preferredLocation.x, screenLocation.y + preferredLocation.y); } else { - toFind = mouseEvent.getLocationOnScreen(); + if (mouseEvent != null) { + toFind = mouseEvent.getLocationOnScreen(); + } else { + toFind = screenLocation; + } } GraphicsConfiguration gc = getDrawingGC(toFind); if (gc == null) { - toFind = mouseEvent.getLocationOnScreen(); - gc = getDrawingGC(toFind); + if (mouseEvent != null) { + toFind = mouseEvent.getLocationOnScreen(); + gc = getDrawingGC(toFind); + } if (gc == null) { gc = insideComponent.getGraphicsConfiguration(); } @@ -301,8 +307,12 @@ public final class ToolTipManager extends MouseAdapter implements MouseMotionLis location.x -= size.width; } } else { - location = new Point(screenLocation.x + mouseEvent.getX(), - screenLocation.y + mouseEvent.getY() + 20); + if (mouseEvent != null) { + location = new Point(screenLocation.x + mouseEvent.getX(), + screenLocation.y + mouseEvent.getY() + 20); + } else { + location = screenLocation; + } if (!leftToRight) { if(location.x - size.width>=0) { location.x -= size.width;