@Override public void paintIcon(Component c, Graphics graphics, int x, int y) { Graphics2D g2 = (Graphics2D) graphics.create(); g2.setColor(Color.WHITE); int width = getIconWidth(); int height = getIconHeight(); g2.drawRect(1, 1, width - 2, height - 2); g2.setFont(font); g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); FontMetrics fm = g2.getFontMetrics(); Rectangle2D bounds = fm.getStringBounds(HELP_STRING, g2); float xPos = (float) ((width - bounds.getWidth()) / 2); int ascent = fm.getAscent(); int descent = fm.getDescent(); float yPos = ((height + 1) / 2 - (ascent + descent) / 2 + ascent); g2.drawString(HELP_STRING, xPos, yPos); g2.translate(-x, -y); } }