Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reservation-1 to 8 digits

 
Tahir Abbas
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to everyone,

My booking form shows one record at a time. The database field Names and values are in JLabels. Only Customer ID value displays in text box. I applied
txtOwner = new JFormattedTextField(new MaskFormatter("########")); on text box to show and get value for Reservation. There are buttons to show next and previous records.

If I input 8 digits in txtOwner but I dont Reserve this record and move to next or previous record that has blank/less than 8 digits in Customer ID field. then txtOwner does not update with new vlaue whenever all other fields get the new value according to new record. txtOwner displays the old value if 8 digits were given. I cannot overwrite this txtOwner with blank or less than 8 digits value.

If I just use * instead of # then it works good for 1-8 alphanumeric characters but you know I just need numeric data.

Thanks!
I'll highly appreciate your help.
Best Regards!
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use a regex to check if the inputs are numeric. I didn't use a MaskFormatter or the JFormattedTextField in my project. What I did was use a DocumentListener on the JTextField and use regex to check.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:What I did was use a DocumentListener on the JTextField and use regex to check.


Me too!
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I used a javax.swing.text.DocumentFilter with a regex to check.

Kind regards,
Roel
 
Johnny Barbosa
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:I used a javax.swing.text.DocumentFilter with a regex to check.

K. Tsang wrote:What I did was use a DocumentListener on the JTextField and use regex to check.

Both are very good. DocumentFilter is better. But, I think that is very sophisticated to this Sun system!
I would prefer something more simple. Like this:
Yes, I know that way, we can't prevent copy and past. But, this don't matter for a simple system.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic