parisa
parisa

Reputation: 842

JFormattedTextField instead of JTextField

In Java, what is the difference between JTextField and JFormattedTextField ? I mean when should I use JFormattedTextField instead of JTextField?

Upvotes: 3

Views: 2480

Answers (3)

ravibagul91
ravibagul91

Reputation: 20755

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

To know more about it Click here and here

Upvotes: 5

carexcer
carexcer

Reputation: 1427

JTextField is used for plain text.

JFormattedTextField is a class that extends from JTextField and it is used to set any format to the text that it contains (in example, phone numbers, e-mails, dates, etc.).

If you don't need to set any special format to the textfield, it's recommendend to use JTextField.

Upvotes: 1

Katana24
Katana24

Reputation: 8959

Have a look at the documentation for JFormattedTextField here, essentially it adds support for formatting arbitrary date values, so it'd would be beneficial when handling date entries

Upvotes: 1

Related Questions