void (Graphics g, ThumbnailComponent tc) { Font font = StartupUiUtil.getLabelFont(); FontMetrics fontMetrics = g.getFontMetrics(font); g.setFont(font); g.setColor(tc.getForeground()); String fileName = tc.getFileName(); String title = fileName; while (fontMetrics.stringWidth(title) > ImagesIcons.ThumbnailBlank.getIconWidth() - 8) { title = title.substring(0, title.length() - 1); } if (fileName.equals(title)) { // Center g.drawString(fileName, 6 + (ImagesIcons.ThumbnailBlank.getIconWidth() - 2 - fontMetrics.stringWidth(title)) / 2, ImagesIcons.ThumbnailBlank .getIconHeight() + 8 + fontMetrics.getAscent()); } else { int dotsWidth = fontMetrics.stringWidth(DOTS); while (fontMetrics.stringWidth(title) > ImagesIcons.ThumbnailBlank.getIconWidth() - 8 - dotsWidth) { title = title.substring(0, title.length() - 1); } g.drawString(title + DOTS, 6, ImagesIcons.ThumbnailBlank.getIconHeight() + 8 + fontMetrics.getAscent()); } }