Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    3

    Question Unanswered: JFormattedTextField()

    I have written a database screen and would like to show the data in a formatted manner.

    When the user inputs the data, it is formatted using

    MaskFormatter mfPhoneNumber = new MaskFormatter();
    JFormattedTextField txtFaxNumber = new JFormattedTextField (mfPhoneNumber);



    ...
    ...

    mfPhoneNumber.setMask("(###) ###-####");
    mfPhoneNumber.setValidCharacters("0123456789");
    ..
    ..

    txtFaxNumber.setText(rs.getString("FaxNumber"));

    This line does not show the text in a formatted way as stated by JFormattedText. But, if I type the numbers 1234567890 -> (123) 456-7890

    So, how to have it format the number read in from the database?

  2. #2
    Join Date
    Jul 2004
    Posts
    2
    I'm afraid that the only way to do this is to format the string manually before setting it to the jFormattedText.

    In your case something like that
    ---------------------------------------------------
    FaxdBString;
    String FormattedString=new String();
    FormattedString="(";
    FormattedString=FormattedString.concat(FaxdBString .subsequence(0,3));
    FormattedString=FormattedString.concat(")");
    ...
    FormattedTextField.setValue(FormattedString);
    --------------------------------------------------
    You can make a function that transforms the original string to fromatted and call it whenever you need it.

Posting Permissions

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