Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Input field for time only!

Input field for time only!

Scheduled Pinned Locked Moved Java
question
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hellboy_83
    wrote on last edited by
    #1

    Hi Guys, I need to format an input field to accept only time with this format: "H:mm:s" How can this be done?

    N F D 3 Replies Last reply
    0
    • H hellboy_83

      Hi Guys, I need to format an input field to accept only time with this format: "H:mm:s" How can this be done?

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      This could be quite an intersting side project, but I think the easiest thing would be a quick google for swing time controls. There are plenty of choices here[^], I wouldn't write your own.


      Panic, Chaos, Destruction. My work here is done.

      1 Reply Last reply
      0
      • H hellboy_83

        Hi Guys, I need to format an input field to accept only time with this format: "H:mm:s" How can this be done?

        F Offline
        F Offline
        fly904
        wrote on last edited by
        #3

        You can assign a KeyListener to the JTextField and perform a quick validation check after a key is typed. Here[^] is a good example of applying the KeyListener.

        If at first you don't succeed, you're not Chuck Norris.

        N 1 Reply Last reply
        0
        • F fly904

          You can assign a KeyListener to the JTextField and perform a quick validation check after a key is typed. Here[^] is a good example of applying the KeyListener.

          If at first you don't succeed, you're not Chuck Norris.

          N Offline
          N Offline
          Nagy Vilmos
          wrote on last edited by
          #4

          If allowed it's simpler to plug in a control to do the job for you.


          Panic, Chaos, Destruction. My work here is done.

          F 1 Reply Last reply
          0
          • N Nagy Vilmos

            If allowed it's simpler to plug in a control to do the job for you.


            Panic, Chaos, Destruction. My work here is done.

            F Offline
            F Offline
            fly904
            wrote on last edited by
            #5

            True, but I haven't come across any controls that format the date like he wants and perform a validation to check it is a valid date. Then again, I haven't looked.

            If at first you don't succeed, you're not Chuck Norris.

            N 1 Reply Last reply
            0
            • F fly904

              True, but I haven't come across any controls that format the date like he wants and perform a validation to check it is a valid date. Then again, I haven't looked.

              If at first you don't succeed, you're not Chuck Norris.

              N Offline
              N Offline
              Nagy Vilmos
              wrote on last edited by
              #6

              fly904 wrote:

              I haven't looked

              I surface skimmed what's on the Sun site.


              Panic, Chaos, Destruction. My work here is done.

              1 Reply Last reply
              0
              • H hellboy_83

                Hi Guys, I need to format an input field to accept only time with this format: "H:mm:s" How can this be done?

                D Offline
                D Offline
                David Skelly
                wrote on last edited by
                #7

                I think JDatePicker supports this format, it certainly has an example in the screenshot on the home page. I'm not sure what it does with the value you enter, though, because Java does not have a Time type. Alternatively, I suppose you could build your own with JFormattedTextField and an InputVerifier or the JGoodies Validation framework.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups