I use the code:

JTextField textField = BasicComponentFactory.createFormattedTextField(valueModel, numberFormatter);

This causes the JTextfield to work very nicely, it automatically changes 512.1!5 to 512.1 with no errors when I commit the trigger that is bound to the presentation model. This is great how smoothly it works but I would like to popup a JDialog saying hey, you inputted 512.1!5 which contained an invalid value so that the user knows exactly what happened. I cannot find a hook in JGoodies Binding to set that up. I tried adding a propertyChangeListener on my PresentatonModel's getBufferedComponentModel() but it would only report values that already had the ! character missing. Therefore I am lost on how to detect a format error, is there some JGoodies bean listener that will allow me to know when to alert the user?

有帮助吗?

解决方案

You can use jgoodies validator interface to validate whatever input there is on that textfield Write your own validator class which implements the following interface. For instance the class name be TextFieldValidator.

Validator<T>

Precondition is that you bind your textfield to a PresentationModel.

TextFieldValidator<T> validator = (TextFieldValidator<T>) getPresentationModel().getValidator();
        validator.setComponent(getYourTextField());

setComponent will set the JTextField reference in TextFieldValidator class and in the validate() method you can show pop ups/change background colors or what not.

Hope that helps.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top