Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Allowing only numbers and dot (.) in a JTextField

807598Mar 17 2006 — edited Nov 6 2007
Hi
I wanna allow only numeric values and dot (.) in my JTextField ...

i m using the following code in the KeyTyped Method which is only allowing numeric values but not allowing dot .
        int value;
       String s;
       s =evt.getKeyText(evt.getKeyChar()) ;
      value = Integer.parseInt(s);
       if(!(value >=0) && (value<=9))
        jtf_amount1.setText(jtf_amount1.getText().substring(0,jtf_amount1.getText().length()-1));
please let me know how to allow the dot as well in my JTextField .
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 4 2007
Added on Mar 17 2006
2 comments
2,603 views