@Override
	public void paint(Graphics g) {
		super.paint(g);

		Insets insets = getInsets();
		int rightEdge = getWidth() - insets.right;
		Rectangle visible = getVisibleRect();
		BigInteger startIdx = pixmap.getIndex(visible.y);
		BigInteger endIdx = pixmap.getIndex(visible.y + visible.height);
		int ascent = g.getFontMetrics().getMaxAscent();
		for (BigInteger i = startIdx; i.compareTo(endIdx) <= 0; i = i.add(BigInteger.ONE)) {
			String text = i.add(BigInteger.ONE).toString();
			int width = g.getFontMetrics().stringWidth(text);
			GraphicsUtils.drawString(this, g, text, rightEdge - width, pixmap.getPixel(i) + ascent);
		}
	}
The built-in provider for the Decompiler's line number margin
Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/margin/LineNumberDecompilerMarginProvider.java