Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between JFormatterTextField and JTextField

 
Avani Joshi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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, (___) ____
 
Brian Cole
Author
Ranch Hand
Posts: 903
1
  • Mark post as helpful
  • send pies
  • 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 ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic