@Override
		public void replace(FilterBypass fb, int offset, int length, String text,
				AttributeSet attrs) throws BadLocationException {

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

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