• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Reservation-1 to 8 digits

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

Kind regards,
Roel
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic