@Override
		public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
			if (str == null) {
				return;
			}
			if (!checkChars(str)) {
				return;
			}
			StringBuilder builder = new StringBuilder(HexOrDecimalInput.this.getText());
			builder.insert(offs, str);
			String newText = builder.toString();

			int lastIndexOf = newText.lastIndexOf('-');
			if (lastIndexOf > 0) {
				return;  // not allowed anywhere except at the start
			}

			if (!newText.equals("-")) {
				try {
					currentValue = computeValueFromString(newText);
				}
				catch (NumberFormatException e) {
					return;
				}
			}
			super.insertString(offs, str, a);
		}
@see javax.swing.text.Document#insertString(int, java.lang.String, javax.swing.text.AttributeSet)
Ghidra/Framework/Docking/src/main/java/docking/widgets/textfield/HexOrDecimalInput.java