When to display error messages for invalid input in Swing application

前端 未结 2 1336
無奈伤痛
無奈伤痛 2020-12-21 16:43

I am using a JFormattedTextField for to format integer input for a Swing app. The default behavior for invalid input is to quietly (i.e. no error message) reset

2条回答
  •  滥情空心
    2020-12-21 17:48

    My first opinion is that showing a JOptionPane to the user whenever the text field focus is lost could be very annoying for users. I would display an error message when the user hits the OK button of your form. The error message could contain a list of all error messages or only the first one and focus the element with the error.

    Another choice would be to use regular JTextField and write your own custom validators. When focus changes, your IntegerValidator (or other implementation) would validate the input string and the UI could display an error or warning icon next to the field, the same as some web applications do.

提交回复
热议问题