File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Difference between JFormatterTextField and JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Difference between JFormatterTextField and JTextField" Watch "Difference between JFormatterTextField and JTextField" New topic
Author

Difference between JFormatterTextField and JTextField

Avani Joshi
Greenhorn

Joined: Jul 09, 2007
Posts: 13
Hi,
Can anyone please tell me the differnce between calling a setDocument method using JFormatterTextField and calling setDocument method using JTextField.

- Thanks in advance
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

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, (___) ____


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
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 ]

    bitguru blog
     
     
    subject: Difference between JFormatterTextField and JTextField
     
    Similar Threads
    JTextField problem
    text editing
    2 textfields 1 model
    Numbers only TextField
    Reg. Validatin JTextFields