• 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
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Difference between JFormatterTextField and JTextField

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can anyone please tell me the differnce between calling a setDocument method using JFormatterTextField and calling setDocument method using JTextField.

- Thanks in advance
 
Sheriff
Posts: 22665
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JFormattedTextField has, as the name implies, a format for the text to be filled in. A JTextField can have any text filled in.

Usually you use JTextField. Only use JFormattedTextField if you need the input to have a specific format, e.g. phone numbers, (___) ____
 
Author
Posts: 979
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JFormattedTextField differs from JTextField in that it can support
  • locale-specific display
  • restrictions on its value
  • editing non-Strings [via setValue(Object)/getValue()]
  • incrementing/decrementing from the keyboard


  • But you ask about specifically about setDocument(), which behaves
    about the same.

    I'd say that it's rare to call setDocument() on a JFormattedTextField.
    Usually one would call setValue() instead, and let the field (and its
    formatter) manage the Document for you.
    [ October 03, 2008: Message edited by: Brian Cole ]
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic