The Artima Developer Community
Sponsored Link

Java Answers Forum
preventing JSpinners from taking non-positive integersh

1 reply on 1 page. Most recent reply: Aug 3, 2004 7:01 AM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Gibran Shah

Posts: 27
Nickname: gibby
Registered: Jun, 2004

preventing JSpinners from taking non-positive integersh Posted: Jul 30, 2004 7:17 AM
Reply to this message Reply
Advertisement
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


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: preventing JSpinners from taking non-positive integersh Posted: Aug 3, 2004 7:01 AM
Reply to this message Reply
Read the document for

SpinnerNumberModel stepSizeModel = new SpinnerNumberModel(0,0,Integer.MAX_VALUE,1);

JSpinner spinner ageSpinner = new JSpinner(stepSizeModel);

This will have only integer as numbers with minumum value 0.

Flat View: This topic has 1 reply on 1 page
Topic: java.servlet.servletexception Previous Topic   Next Topic Topic: Java Applets... are they making a come back?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use