Re: Formatted text field

From: Andrew Thompson (andrew64_at_bigNOSPAMpond.com)
Date: 12/20/03


Date: Sat, 20 Dec 2003 18:57:19 GMT


"John M" <bali1a@freemail.hu> wrote in message
news:hsXEb.151792$dt3.78933@news.chello.at...
> 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


Relevant Pages

  • Re: Larger field than thought?
    ... I need to generate automated account numbers for a new ... As I see it, I can change the above routine to check for 4 digits, instead ... Some form of loop to go through all parts in the database ... John W. Vinson/MVP ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Variable type to hold largest whole number
    ... John wrote: ... reach the limit of what a variable type can hold and lets say add 1, ... special classes (free or commercial to hold very large numbers ... If you want to go above 28 digits, you'll need to use a 3rd party class ...
    (microsoft.public.dotnet.general)
  • Re: Limit characters in an Input Box
    ... Charles Chickering ... jking80 wrote: ... I need to ensure the user enters only 3 digits into the text box. ... Also, if the user types in only one or two digits, the program ...
    (microsoft.public.excel.programming)
  • question about the loves algorithm
    ... I have a somewhat practical and maybe silly question about the 'loves' algorithm. ... For each character in the word 'loves', count the total number of occurences in both names 'John' and 'Jane'. ... Then start adding subsequent digits until a 2 digit number is obtained, ...
    (sci.math)
  • Re: question about the loves algorithm
    ... I have a somewhat practical and maybe silly question about the 'loves' ... Let me explain first what the algorithm is. ... is John, and you like a girl named Jane. ... the number of digits seems to grow ...
    (sci.math)