Bookmark Topic Watch Topic
  • New Topic

NX:Formatted textField

 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi
Could someone please post an example of formatted text field to validate user input? (using Document )(for example, just to take 8 numbers from user)
Thanks,
Manoj
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Manoj,

And then set the document to your textfield.
Best,
Vlad
 
Arun Kumar
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Report post to moderator
Use regular expressions to check if the entered value is valid. If not pop a message saying what is expected from the user.
Arun
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Report post to moderator
try this:
this.bookField = new JFormattedTextField(new
MaskFormatter("########"));
bookField.setFocusLostBehavior(JFormattedTextField.PERSIST);
 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Report post to moderator
Vlad, thanks for the code. It helped me to grasp the concept too.
But later I realized that this will not solve my problem, as I am using
JOptionPane.showInputDialog. This was a very easy option.
But as this shows its own default textfield, I could not find a way to setDocument to it's default textfield.
If I try to add a new textfield to this, it shows 2 text field, one my own and 2nd it's default one.
Is there any way to set the Document to the showInputDialog's default textfield? I could not find anything in the API.
The other option to create the customized optionpane involves too much of code, which I dont want to do just for this small purpose.

And thanks to Bill too for the code snippet. I guess now instead of setDocument one could (or should) use the JFormattedTextField, as this is in the new API (1.4) I am not sure if it is ok, when one says that his/her assignment is developed on the latest version (like 1.4.1 or 2) and still use the setDocument and not the JFormattedTextField.
Thanks,
Manoj
[ October 07, 2003: Message edited by: Jmannu gundawar ]
 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can somone help me out
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Report post to moderator
Manoj,
I have closed this topic. It seems you are asking the same question in this one as you asked in the topic "Book Number text field
In this thread Vlad has been kind enough to post code showing how to use a Document to validate the field. In the other thread Mark has been kind enough to post code showing how to validate the field.
In both threads Bill Robertson has been kind enough to show how to use the JFormattedTextField and MaskFormatter (assuming you are using J2SE 1.4 - which you should be doing).
So there is nothing in this thread that is not in the other thread. The other thread has some other items of interest to those doing the Fly By Night Services assignment, so I am leaving that one open.
Regards, Andrew
 
    Bookmark Topic Watch Topic
  • New Topic