Idea for auto-validating text field, done already or not?

  • Thread starter Robert Maas, see http://tinyurl.com/uh3t
  • Start date
R

Robert Maas, see http://tinyurl.com/uh3t

Recently in thinking about an application I'd like to write, I realized
that it would be good to have the following kind of JComponent:

There's a sub-class of JPanel which contains a JTextField and a
JButton. The component has a list of validators for the text field.
Whenever the user types text into or otherwise modifies the text field,
the background color changes to yellow, to indicate it hasn't yet been
validated. Whenever the user starts to move the mouse, indicating
he/she is finished with editing there, or pauses for longer than some
threshold, the list of validators are run against the current contents
of the text field, each inside a try block, and the first that succeeds
causes the label to be changed to say what kind of syntax was
recognized (for example, integer, double float, string-literal,
s-expression, etc.) and causes the background of the editable text
field to turn light green or perhaps some selected color depending on
the type of data shown. But if all validators fail, the background goes
pink and the label goes *invalid* or somesuch. Then when editing
resumes, background goes yellow again and label goes invisible again.

When the text field is valid the button would be activated such that
pressing it would cause an action event whereby the parsed object from
the text field is entered onto the stack of a RPN calculator or other
practical use within the overall application. When the text field is
yellow (in-edit) or pink (invalid), the button would not be active.

This would be a bit of work to implement, so before I start, has this
already been done, where I should just copy what's already done and
build my overall application upon it? Or is it a new idea that I should
be the first to implement?
 
D

Dale King

Robert said:
Recently in thinking about an application I'd like to write, I realized
that it would be good to have the following kind of JComponent:

There's a sub-class of JPanel which contains a JTextField and a
JButton. The component has a list of validators for the text field.
Whenever the user types text into or otherwise modifies the text field,
the background color changes to yellow, to indicate it hasn't yet been
validated. Whenever the user starts to move the mouse, indicating
he/she is finished with editing there, or pauses for longer than some
threshold, the list of validators are run against the current contents
of the text field, each inside a try block, and the first that succeeds
causes the label to be changed to say what kind of syntax was
recognized (for example, integer, double float, string-literal,
s-expression, etc.) and causes the background of the editable text
field to turn light green or perhaps some selected color depending on
the type of data shown. But if all validators fail, the background goes
pink and the label goes *invalid* or somesuch. Then when editing
resumes, background goes yellow again and label goes invisible again.

Take a look at javax.swing.JFormattedTextField which was created for
validating text entry fields.
 
R

Robert Maas, see http://tinyurl.com/uh3t

From: Dale King said:
Take a look at javax.swing.JFormattedTextField which was created for
validating text entry fields.

It's my impression from reading the API documentation that it's capable
of validating only one kind of data per text field, nothing at all like
what I suggested where the user can type in any of several different
syntaxes for different data types and the text field subclass would
check down the list of data types to find the first that matches and
perform a different event action for each different such match.

If somebody would please help me get my laptop's modem working again, I
might program a simple applet to demonstrate what I have in mind, and
then upload it to an accesible Web site so you could play with it.
 
D

Dale King

Robert said:
It's my impression from reading the API documentation that it's capable
of validating only one kind of data per text field, nothing at all like
what I suggested where the user can type in any of several different
syntaxes for different data types and the text field subclass would
check down the list of data types to find the first that matches and
perform a different event action for each different such match.

You can write your own AbstractFormatter to validate to any criteria you
want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top