4. Use a JTextField that does not allow too many characters to be entered.
There are several places that a component appears in an application. It must be declared, have tooltips and other values set, set on the screen with various options, filled with data, checked to see if it has data if it is a required field and a save is happening, reset after a save, and cleared if an ADD is going to happen.

Hear is some example code from the UserLogData class generated by JGuigen.

Set JFormattedTextfield mask - Telephone - set JFormattedTextfield mask - This also sets a default phone number (e.g. (000) 000-0000) the user can type over. RegEx masks are almost required to work this way and formatted masks are easier for users to visualize when they have a target format in front of them. These are stored in the resource bundle so they can be changed from one locale to another.

Code is also generated here to demonstrate moving the caret position to a certain location when the field gains focus. Note that it requires both a mouselistener and a focuslistener.

·

Check for data if this is a required field - this is just like the text for a bounded text field, except JFormattedtextfields can use x.getValue().toString() instead of x.getText() when retrieving data from the component.

Get data from SQL resultSet - Telephone - get data from SQL resultSet - note that a JFormattedTextField must use x.setValue(string) instead of x.setText(string) to put data into the component. x.setText(string) will work but always rings the "invalid data" bell.

Note that the hot keys are stored in the resource bundle. This allows the hot key letter to be changed from one language to the next. The letter used for a hot key in one language may not even be present in the word used in another language.