preventing JSpinners from taking non-positive integers


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: preventing JSpinners from taking non-positive integers

  1. #1
    Join Date
    Jun 2004
    Posts
    29

    preventing JSpinners from taking non-positive integers

    Hello,

    I want to program a JSpinner such that the user cannot enter anything other than positive integers. As it stands now, a JSpinner is like a glorified JTextField in that the user can enter whatever characters (s)he wants. I'm using it to enter a person's age, so I want to prevent users from entering values like "abc". I'd much rather do this than implement sophisticated error checking once the user hits submit. Is there any example code online that shows how to do this? Can anybody tell me straight out how to do this?

    Gibran

  2. #2
    Join Date
    Feb 2004
    Posts
    808
    set the spinner model to be a SpinnerNumberModel bouded from 0 to MAX_INTEGER, starting at.. er.. 1?

    read http://java.sun.com/j2se/1.4.2/docs/...mberModel.html
    and try JSpinner.setModel(...)
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center