Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / August 2003

Tip: Looking for answers? Try searching our database.

"dd/MM/yy", "AAA", "!AA", "hh:mm:ss" inside jTextFields

Thread view: 
Costis Aivalis - 12 Aug 2003 10:07 GMT
is there a way to enforce such patterns as a rule during dataentry in
swing?

Thank you
Costis Aivalis
Peter Schoaff - 12 Aug 2003 16:48 GMT
> is there a way to enforce such patterns as a rule during dataentry in
> swing?
>
> Thank you
> Costis Aivalis

Create a Document class which extends something like
javax.swing.text.PlainDocument.  In this document override insertString
and put whatever rules you want to enforce there.

Then setDocument on the data entry field to an instance of this new class.
Tor Iver Wilhelmsen - 12 Aug 2003 17:54 GMT
> is there a way to enforce such patterns as a rule during dataentry in
> swing?

Use an InputVerifier, or for 1.4.x use a JFormattedTextField.
Peter Schoaff - 13 Aug 2003 00:58 GMT
> > is there a way to enforce such patterns as a rule during dataentry in
> > swing?
>
> Use an InputVerifier, or for 1.4.x use a JFormattedTextField.

I'd missed that addition to 1.4. It's a much better solution than mine.
Please disregard my previous answer ;-)
Costis Aivalis - 13 Aug 2003 09:06 GMT
>>>is there a way to enforce such patterns as a rule during dataentry in
>>>swing?
[quoted text clipped - 3 lines]
> I'd missed that addition to 1.4. It's a much better solution than mine.
> Please disregard my previous answer ;-)

Thanx to all!

i am aware of the InputVerifier class. It gives an acceptable
after-entry control.

I am trying though, to force the user to enter the right type of data or
_beep_ during data entry.

I wanted to avoid writing my own controls to check every character
entered like a did a few years back in C, and i was hoping that this
would be already implemented, so that the rules could easily be set for
the SunOne-Forte or NetBean GUIS.

It is a perpetual necessity for every application. Even VB comes with
this feature i think they call it a data=entry-mask or something.

Costis Aivalis
David Segall - 13 Aug 2003 13:58 GMT
>>>>is there a way to enforce such patterns as a rule during dataentry in
>>>>swing?
[quoted text clipped - 19 lines]
>It is a perpetual necessity for every application. Even VB comes with
>this feature i think they call it a data=entry-mask or something.
VB does come with this "feature" and it shows an infuriating disregard
for modern user interfaces. It ignores the fact the user can use the
mouse to enter data anywhere in the field in any order they choose. If
I want to enter the year before I enter the day and month or cut and
paste a temporarily invalid figure from a U.S. spreadsheet into a
European application, I should be allowed to. The feature was
invaluable on card and paper tape punches; now it's time to let the
user decide how to enter the field and check it when (s)he has
finished.

>Costis Aivalis
Roedy Green - 14 Aug 2003 05:44 GMT
>he feature was
>invaluable on card and paper tape punches; now it's time to let the
>user decide how to enter the field and check it when (s)he has

If you paste into subfields, you can still warn of errors at the time
of paste or of keystroke.  The general rule is, the sooner the error
is reported the easier it is to correct.  It also tends to build more
accurate typing reflexes.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
David Segall - 14 Aug 2003 15:37 GMT
>>he feature was
>>invaluable on card and paper tape punches; now it's time to let the
[quoted text clipped - 4 lines]
>is reported the easier it is to correct.  It also tends to build more
>accurate typing reflexes.
I cannot disagree with your "general rule". However, it is very
irritating if I attempt to paste 1,234,456.78 into a European program
and have it  rejected before I get the chance to change the commas to
full stops and vice versa. The subfield idea also limits cutting and
pasting as you will have found if you have tried to paste the 19
character serial number of your Microsoft program from the text file
on the "gold" CD into the 4 character subfield. :)
Roedy Green - 14 Aug 2003 23:38 GMT
>if I attempt to paste 1,234,456.78 into a European program
>and have it  rejected before I get the chance to change the commas to
>full stops and vice versa.

There are several ways the reject could be done.

1. reject the paste as if it never happened. The problem with this is
the user is at  loss to know precisely what the matter is, or to be
able to correct it.

2. accept the paste, but ignore the invalid chars in the paste,
leaving the originals in place.  You might replace the invalid chars
with spaces or something else appropriate.

3. accept the paste but highlight the invalid characters. Don't accept
the field until those are fixed.  It is still good to let the user
know as soon as possible the error has been made, even if you don't
force him to fix it immediately.

4. For individual keystroke errors, I find the kindest way to deal
with invalid keystrokes is just to ignore them and make a tiny blip
noise. You can do some friendly things, like convert letters to
numbers in phone number fields in case people are giving you cute
mnemonics. You can auto upper or autolower case, and not complain if
the user types the opposite.   You can auto hop over spaces and other
decorative punctuation in fields so that the user does not have to
type it or space over it.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Tor Iver Wilhelmsen - 13 Aug 2003 15:15 GMT
> I am trying though, to force the user to enter the right type of data
> or _beep_ during data entry.

Borland's JBCL components have this if you have an older JBuilder Pro
or Enterprise available.
Roedy Green - 12 Aug 2003 19:59 GMT
>is there a way to enforce such patterns as a rule during dataentry in
>swing?

for dates there is SimpleDateFormat.parse.  see
http://mindprod.com/jgloss/calendar.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.