Other Top Part of Screen Items
[Previous] [Main] [Next]

Other Top Part of Screen items.




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.

·Instantiate the component - Bounded Text Field Example - declare the field ·  
·Set ToolTips and Assistive Technology name/description - Bounded Text Field Example - set ToolTips and Assistive Technology  
·Add to layout manager - Bounded Text Field Example - add to layout manager  
·Test for data if a required field - Bounded Text Field Example - Test for data if required  
·Test if data changed, set up SQL Update and Insert strings - Bounded Text Field Example - Test if data changed, set up update & insert strings ·  
·Fill component from resultSet - Bounded Text Field Example - Fill component from resultSet  
·Reset the string that holds the original value if data is saved to SQL table - Bounded Text Field Example - Reset hld value to value in component after save  
·Set component to default value from SQL table when the CLEAR button is pressed - Bounded Text Field Example - Set component to default value when CLEAR is pressed  

5. Using a special border (dashed, red) to indicate required fields
· Add to layout manager - Bounded Text Field Example - add to layout manager  
·Method to create dashed red border - Bounded Text Field Example - add to layout manager  
The reason for using a dashed border is for color blind users who cannot see the red border.  

6 Making a field non-editable
·Add to layout manager - Bounded Text Field Example - add to layout manager     
Most components have either setEditable(boolean) and/or setEnabled(boolen) methods.        

7. Placing tooltips on each components
·Set ToolTips and Assistive Technology name/description - Bounded Text Field Example - set ToolTips and Assistive Technology  

8. Forcing proper format of phone numbers - Cursor/Caret Placement in Component
·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 component - set default (e.g. (000) 000-0000) to blank - Telephone - get data from 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.  
·Resetting the hld string is just like the Bounded Text field.  
·Set phone to default phone number when screen is cleared getting ready for an ADD - Telephone - set phone to default value with CLEAR button is pressed  
 
9. Hot Key Associated with JTextFields  
·Add to layout manager - Bounded Text Field Example - add to layout manager  
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.  
 
10. Loading data from SQL back end
·Fill component from resultSet - Bounded Text Field Example - Fill component from resultSet  
Look at the UserLogDataTableModel file to set how the data is loaded directly from the resultSet rather than being loaded into a vector or Arraylist.  
 
14. Generating a JUnit TestCase program to test the GUI  
   More on this later.