This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 19651
    
  18

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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Difference between JFormatterTextField and JTextField
     
    Similar Threads
    Reg. Validatin JTextFields
    text editing
    JTextField problem
    2 textfields 1 model
    Numbers only TextField