IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
Author

JFormattedTextField validation

Nicol Green
Ranch Hand

Joined: Jan 30, 2010
Messages: 55

When I was thinking which to choose JTextField or JFormattedTextField I thought that it would be much easier to program JFormattedTextField, it's name says that, too but now I am dealing with some problems. I consider that should be possible quickly to be done, but not here..

I have a



I would like to say:

1. inputLenght, not longer then for example 20.
2. Still I cannot use FormattedFactory, because of that initial value. setEditable, or setEnabled is not working in this case.

I feel that it is some trivial solution, or, I hope! So, any tips are welcome! Thank you!
Campbell Ritchie
Bartender

Joined: Oct 13, 2005
Messages: 14987

Don't know. I presume you have looked for tutorials like this one?

I think this thread would sit better on our GUIs forum, so I shall move it.
Michael Dunn
Rancher

Joined: Jun 09, 2003
Messages: 3093

a JTextField with DocumentFilter set might suit you better
pete stein
Ranch Hand

Joined: Feb 23, 2007
Messages: 915

Or perhaps all you need to do is use a standard JTextField and simply parse the textfield's text within a try/catch block, catching for NumberFormatException.

This message was edited 1 time. Last update was at by pete stein

Nicol Green
Ranch Hand

Joined: Jan 30, 2010
Messages: 55

Yes definitely, JFormattedTextField was not the best option in my case. I will try what you proposed, and than tell you what was the best solution.

Thanks!
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
IntelliJ open source