Results 1 to 2 of 2
  1. #1
    teracomp is offline Member
    Join Date
    Jan 2008
    Posts
    3
    Rep Power
    0

    Default JFormattedTextField Issue

    I'm using JFormattedTextFields to automatically manage several numeric text fields on an Applet. When the Applet's form is processed the data is collected from the form and written to a MySql database. Each text box is then set to blank, i.e., field.setText("").

    So far, so good. However, if I click in the blank text box then click somewhere else, the value that was previously entered will reappear. This if very problematic.

    I found the answer while preparing the post, but it might be useful to someone, so here's the solution.

    The default behavior for losing focus is COMMIT_OR_REVERT
    Apparently, the component recalls the last valid entry in the field when focus is lost. Sounds like a feature, but a big problem for me.

    To fix this, I set the lost focus behavior for each field declared as a JFormattedTextField, e.g.: field.setFocusLostBehavior(JFormattedTextField.PER SIST);

    Having said that, if anyone knows of a problem with this solution, please chime in!

  2. #2
    teracomp is offline Member
    Join Date
    Jan 2008
    Posts
    3
    Rep Power
    0

    Default

    big OOPS! PERSIST is the wrong value; COMMIT is the proper way of handling this. Using PERSIST effectively short circuits the formatter (bad idea).

    The code was changed to:
    field.setFocusLostBehavior(JFormattedTextField.COM MIT);

    And the behavior is what I required by default.

    Still, let me know if anyone is aware of other JFormattedTextFields properties I should be concerned with . Thanks.

Similar Threads

  1. Alignment Issue...
    By chanduseec in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 09-30-2008, 07:47 AM
  2. Issue with Buttons and ActionPerformed
    By Deathmonger in forum Advanced Java
    Replies: 1
    Last Post: 04-17-2008, 09:47 AM
  3. Try Catch issue
    By curtis_fraser in forum Advanced Java
    Replies: 2
    Last Post: 12-14-2007, 12:04 AM
  4. Issue
    By chaitu444 in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 08:49 PM
  5. compilation issue
    By orchid in forum Eclipse
    Replies: 2
    Last Post: 04-20-2007, 01:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •