@Override
		public void insertString(FilterBypass fb, int offset, String text, AttributeSet attr)
				throws BadLocationException {

			// form a string that is the current document text with the inserted new text
			text = text.replace('X', 'x');
			StringBuilder builder = getText(fb);
			builder.insert(offset, text);

			// if the newly formed text is valid, allow the operation
			if (isValid(builder)) {
				super.insertString(fb, offset, text, attr);
			}
		}
DocumentFilter that prevents users from entering invalid data into the field.
Ghidra/Framework/Docking/src/main/java/docking/widgets/textfield/IntegerTextField.java