Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Formatted text field

Reply
Thread Tools

Formatted text field

 
 
John M
Guest
Posts: n/a
 
      12-20-2003
Hello,

how is it possible to enable only numbers input in a jFormattedTextField?
I use now this code:
JFormattedTextField jFormattedTextField1 = new JFormattedTextField(new
DecimalFormat());

But in this case user can enter any character and the decimal conversion
comes after leaving the cell.
I want that user can enter only digits.

Thanks!


 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      12-20-2003
John M wrote:
> Hello,
>
> how is it possible to enable only numbers input in a jFormattedTextField?
> I use now this code:
> JFormattedTextField jFormattedTextField1 = new JFormattedTextField(new
> DecimalFormat());
>
> But in this case user can enter any character and the decimal conversion
> comes after leaving the cell.
> I want that user can enter only digits.
>
> Thanks!


You need to refer to the javadocs first! There's an example of using
an InputVerifier in the JFormattedTextField page which address
precisely what you are asking. Save the bandwidth for the thorny
ones, please.

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      12-20-2003
"John M" <(E-Mail Removed)> wrote in message
news:hsXEb.151792$(E-Mail Removed)...
> Hello,
>
> how is it possible to enable only numbers input in a jFormattedTextField?
> I use now this code:
> JFormattedTextField jFormattedTextField1 = new JFormattedTextField(new
> DecimalFormat());
>
> But in this case user can enter any character and the decimal conversion
> comes after leaving the cell.
> I want that user can enter only digits.


Som is '-1' valid for your field, it is an integer,
but does not consist of only digits..

If you _only_ need digits, you might try this..

Add a keylistener to a textfield. Parse the
contents as an integer on each keypress, if
that throws an exception get the text of the
field, trim it by 1, put it back and inform the user..

[ This has some problems if the user types
987, then arrows back 9 and types a,
but I think you get the idea.. ]

HTH

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


 
Reply With Quote
 
ak
Guest
Posts: n/a
 
      12-21-2003
> how is it possible to enable only numbers input in a jFormattedTextField?

you can have only numbers also in JTextField.
Use Document which accepts only digits. It is much better then KeyListener.


____________

http://reader.imagero.com the best java image reader.


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-21-2003
"ak" <(E-Mail Removed)> wrote in message news:bs2q78$ve6$(E-Mail Removed)...
> > how is it possible to enable only numbers input in a

jFormattedTextField?
>
> you can have only numbers also in JTextField.
> Use Document which accepts only digits. It is much better then

KeyListener.

This was about integers, right?

'-3' and '1.73E+3' are both integers,
...aren't they (shrugs)?


 
Reply With Quote
 
ak
Guest
Posts: n/a
 
      12-21-2003
> > you can have only numbers also in JTextField.
> > Use Document which accepts only digits. It is much better then

> KeyListener.
>
> This was about integers, right?
>
> '-3' and '1.73E+3' are both integers,
> ..aren't they (shrugs)?
>

ok, not only digits. Use DecimalFormat _in_ Document of JTextField.

____________

http://reader.imagero.com the best java image reader.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
1.Enter space bar for field names and save the field.The field shoud not get saved and an alert should be there as"Space bars are not allowed" Sound Javascript 2 09-28-2006 02:43 PM
Placing the selection of a list field in a text field Jerry Manner HTML 5 06-09-2005 01:52 PM
Help: Sort Date dg col , Add formatted field to a ds? JDP@Work ASP .Net Web Controls 0 02-19-2005 07:49 AM
retrieving formatted messages from an ACCESS memo field. Hugh Welford ASP General 3 05-21-2004 03:07 PM



Advertisments