@Override
	public void paintIcon(Component c, Graphics g, int x, int y) {
		g.setColor(Colors.BACKGROUND);
		g.fillRect(x, y, getIconWidth(), getIconHeight());
		g.setColor(BORDER_COLOR);
		g.drawRect(x, y, getIconWidth(), getIconHeight());

		float fontSize = getMaxFontSize(g, getIconWidth() - 1, getIconHeight());
		Font originalFont = g.getFont();
		Font textFont = originalFont.deriveFont(fontSize).deriveFont(Font.BOLD);
		g.setFont(textFont);

		FontMetrics fontMetrics = g.getFontMetrics(textFont);
		Rectangle2D stringBounds = fontMetrics.getStringBounds(number, g);
		int textHeight = (int) stringBounds.getHeight();
		int iconHeight = getIconHeight();
		int space = y + iconHeight - textHeight;
		int halfSpace = space >> 1;
		int baselineY = y + iconHeight - halfSpace;// - halfTextHeight;// + halfTextHeight;

		int textWidth = (int) stringBounds.getWidth();
		int iconWidth = getIconWidth();
		int halfWidth = iconWidth >> 1;
		int halfTextWidth = textWidth >> 1;
		int baselineX = x + (halfWidth - halfTextWidth);

		g.setColor(Colors.FOREGROUND);
		JComponent jc = null;
		if (c instanceof JComponent) {
			jc = (JComponent) c;
		}
		GraphicsUtils.drawString(jc, g, number, baselineX, baselineY);
	}
An icon that paints the given number
Ghidra/Framework/Docking/src/main/java/docking/resources/icons/NumberIcon.java