private int getBestWidth() {
			Font font = getFont();
			FontMetrics fm = getFontMetrics(font);
			int stringWidth = fm.stringWidth(rawText);

			// 
			// Make a width that is at least as big as the width of the text.  Use the preferred
			// width, as that is more accurate.  Do not do this for the FlatLaf UIs because their
			// preferred width includes a minimum width which will be too large for a small number
			// of characters.
			//
			Dimension preferred = super.getPreferredSize();
			int width = stringWidth;
			if (!LookAndFeelUtils.isUsingFlatUI()) {
				width = Math.max(stringWidth, preferred.width);
			}

			// a fudge factor to compensate for text calculation rounding, based on a 12pt font size
			Insets insets = getInsets();
			width += insets.left + insets.right;
			return width;
		}
A text pane that can render links.
Ghidra/Framework/Docking/src/main/java/docking/widgets/GHyperlinkComponent.java