File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TextFields Input

 
Ramgopal Reddy
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Kristof Janssens
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thans Dear Friend,
But i would like to Develop that aplication with AWT.
If possible tell me buddy!
 
Bruce Xu
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
B Chen
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing forum. Please keep this forum for SCJD topics.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic