void () { if (myLayoutBaseComponent == null || myPopupBalloon == null) { // if no component set - use default location on the LayeredPane if (myPopupBalloon != null) { myPopupBalloon.setBounds(null); } return; } Dimension layeredSize = Objects.requireNonNull(layeredPane).getSize(); Dimension size = new Dimension(myPopupBalloon.getPreferredSize()); Point location = SwingUtilities.convertPoint(myLayoutBaseComponent, 0, 0, layeredPane); int x = layeredSize.width - size.width; int fullHeight = location.y; if (x > location.x) { x = Math.max(location.x - 20, 0); } if (size.height > fullHeight) { size.height = fullHeight; } int locationX = x; int locationY = fullHeight - size.height; if (ShadowJava2DPainter.Companion.enabled()) { locationX -= JBUI.scale(10); if (size.height < fullHeight) { locationY -= JBUI.scale(5); } } myPopupBalloon.setBounds(new Rectangle(locationX, locationY, size.width, size.height)); }