String (@NotNull String text, @NotNull FontMetrics metrics, int maxWidth) { int width = metrics.stringWidth(text); if (width <= maxWidth) return text; while (width > maxWidth && text.length() > MIN_TEXT_LENGTH) { text = text.substring(0, text.length() - 1); width = metrics.stringWidth(text + "..."); } return text + "..."; }