Results 1 to 6 of 6
  1. #1
    JavaTrouble is offline Member
    Join Date
    May 2010
    Posts
    16
    Rep Power
    0

    Default jField date range

    Hello,

    I'm new to Java, so i don't really know how to start what i want to do.

    How do I set a date range. I work with jFrame, so the date will be typed into a jField. I want the user to type in dates that are whithin a range e.g. between 1990 and 2000 - all other dates should be refused.
    How do i go about doing that? What do i need?
    please help

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default

    Quote Originally Posted by JavaTrouble View Post
    Hello,

    I'm new to Java, so i don't really know how to start what i want to do.

    How do I set a date range. I work with jFrame, so the date will be typed into a jField. I want the user to type in dates that are whithin a range e.g. between 1990 and 2000 - all other dates should be refused.
    How do i go about doing that? What do i need?
    please help
    Don't use just a JTextField for that; use its more specialized JFormattedTextField subclass instead.

    kind regards,

    Jos

  3. #3
    JavaTrouble is offline Member
    Join Date
    May 2010
    Posts
    16
    Rep Power
    0

    Default

    I've never used JFormattedTextField - what would the rough code be

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default

    Quote Originally Posted by JavaTrouble View Post
    I've never used JFormattedTextField - what would the rough code be
    Come to think of it: a JFormattedTextField can't do a range (interval) of values; better use a JSpinner instead using a SpinnerDateModel. All the code has been written for you. Read the API documentation for those classes how to assemble the different objects.

    kind regards,

    Jos

  5. #5
    JavaTrouble is offline Member
    Join Date
    May 2010
    Posts
    16
    Rep Power
    0

    Default

    sorry i don't understand how a spinner would work because the user is entering the data in, in the format of ddmmyyyy
    i just want to know how the code would be like. I suppose its a straight forward code but I just dont know how to constrct it

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    12

    Default

    Did you read the API? Did you follow the link to the Swing tutorial for working examples that use a JSpinner?

    If you need more help post your SSCCE that shows the problem.

Similar Threads

  1. In-Range adder
    By filem_funk in forum New To Java
    Replies: 1
    Last Post: 11-27-2009, 01:06 AM
  2. Range within an Array
    By End in forum New To Java
    Replies: 6
    Last Post: 04-18-2009, 06:53 PM
  3. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  4. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM
  5. Can I set a range in case statement?
    By christina in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •