wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JTextField problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField problem" Watch "JTextField problem" New topic
Author

JTextField problem

Tony Shi
Greenhorn

Joined: Oct 02, 2003
Posts: 3
Hi,
I wnat to create a JTextField that accepts 0-9 only. I tried the following code,

it worked, but jTextField.selectAll() and jTextField.setText("String") stopped working. I can't seem to figure out the reason. Can someone please help?
Thanks a lot!
Jason O' Regan
Greenhorn

Joined: May 26, 2003
Posts: 3
You should implement a Document that only accepts numeric values,
by subclassing the javax.swing.text.PlainDocument class and overriding the insertString method there. Then add this Document to the JTextField using the setDocument method.


--------------------------<br />Jason O'Regan<br />SCJP, SCJD, SCWCD, SCBCD, SCEA.<p>Artificial intelligence is no match for natural stupidity.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTextField problem
 
Similar Threads
Searching string in an array.
JTextField In JTable Value Update Problem
Disappointed with JFormattedTextField
Custom Formats JFormattedTextField
hashcode()...