3

I need JTextArea, not JFormattedTextField, because I want 3 lines and on each lines one digits, how can I do it?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user1628407
  • 139
  • 2
  • 8

1 Answers1

5

Extract the Document from the JTextArea, cast it to a PlainDocument and then add a DocumentFilter to the Document, filtering out all un-allowed input.

Please click this link for the Document Filter Tutorial.

For an example of the opposite, a DocumentFilter which prevents the user from typing numbers into the document, please see: Using DocumentFilter.FilterBypass. It would be easy to adapt this to your needs.

Community
  • 1
  • 1
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373