В зависимости от того, что вам нужно, что-то вроде этого может работать для вас:
myTextField.setInputVerifier(new InputVerifier() {
@Override
public boolean verify(JComponent input) {
JTextField textField = ((JTextField) input);
try {
Float isFloat = Float.valueOf(textField.getText());
textField.setBackground(Color.WHITE);
return true;
} catch (NumberFormatException e) {
textField.setBackground(Color.RED);
return false;
}
}
});