• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TextFields Input

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai am wanna like to know about TextFields Input type.
Now i would like to give input as a numbers.
So i don't want allow alphabets in that field how its possible?
plz send sample code to me.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could have used google to find this one ... did you even search?

anywhy, here you find an example:
http://www.java2s.com/Code/Java/Swing-JFC/Textfieldonlyacceptsnumbers.htm
 
Ramgopal Reddy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thans Dear Friend,
But i would like to Develop that aplication with AWT.
If possible tell me buddy!
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I prefer using JFormattedTextField.
Hopefully following can give u some hints.
----------------------------------------
import javax.swing.JFormattedTextField
import javax.swing.text.DefaultFormatterFactory;
import java.text.NumberFormat;
import javax.swing.text.NumberFormatter;
...
NumberFormat format = NumberFormat.getNumberInstance();
format.setMaximumIntegerDigits(3);
NumberFormatter formatter = new NumberFormatter(format);
formatter.setAllowsInvalid(false);
formatter.setMinimum(new Integer(0));
formatter.setMaximum(new Integer(255));
...
------------------------------------------
If you need more flexible&custmozied requirements, you probably need to overwrite some functions of "Formatter" or create you owner "Format" class.

here is the official tutorial:
http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ramgopal Reddy:
Thans Dear Friend,
But i would like to Develop that aplication with AWT.
If possible tell me buddy!



Check your instructions. I believe you must use Swing for all your GUI components.
Another way to do it is to add KeyListener to JTextField to check the input character. Consume the event if the character is not a digit.

[ March 17, 2006: Message edited by: B Chen ]
[ March 17, 2006: Message edited by: B Chen ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Swing forum. Please keep this forum for SCJD topics.
reply
    Bookmark Topic Watch Topic
  • New Topic