void (final @NotNull JLabel label, final @NotNull Graphics g, @Nullable Rectangle bounds) { if (bounds == null) { bounds = getLabelTextBounds(label); } // JLabel draws the text relative to the baseline. So, we must ensure // we draw the dotted rectangle relative to that same baseline. FontMetrics fm = label.getFontMetrics(label.getFont()); int baseLine = label.getUI().getBaseline(label, label.getWidth(), label.getHeight()); int textY = baseLine - fm.getLeading() - fm.getAscent(); int textHeight = fm.getHeight(); drawDottedRectangle(g, bounds.x, textY, bounds.x + bounds.width - 1, textY + textHeight - 1); }