0

Possible Duplicate:
Best way to constrain user to enter a time in a JTextField

I Use window builder in Eclipse, I've a JTextField and i want to set the hour as text (hh:mm:ss). I've some troubles; does anybody can help me? thank you

Community
  • 1
  • 1
Nerd
  • 175
  • 1
  • 3
  • 8
  • *"I've some troubles;"* For better help sooner, post an [SSCCE](http://sscce.org/) & copy/paste any exception that results from it. – Andrew Thompson Dec 07 '12 at 19:23
  • 1
    `JTextField.setText( "hh:mm:ss" )`. That is about all I can make from this question – Robin Dec 07 '12 at 19:30
  • 1
    I think you may want a [`JFormattedTextField`](http://docs.oracle.com/javase/7/docs/api/javax/swing/JFormattedTextField.html) see this answer for example: http://stackoverflow.com/questions/11881301/best-way-to-constrain-user-to-enter-a-time-in-a-jtextfield/11881523#11881523 – David Kroukamp Dec 07 '12 at 19:38
  • As an "example", you could have a look at [this](http://stackoverflow.com/questions/11881301/best-way-to-constrain-user-to-enter-a-time-in-a-jtextfield/11881681#11881681) - it is a prototype, so it needs some more work, but it might inspire – MadProgrammer Dec 07 '12 at 21:20

1 Answers1

0

use java date & time. example:

import java.util.*;
...
  // Create a Gregorian calendar initialized
  // with the current date and time in the
  // default locale and timezone.
  GregorianCalendar gcalendar = new GregorianCalendar();

  String hr = ("" + gcalendar.get(Calendar.HOUR) + ":");
  String min = ("" + gcalendar.get(Calendar.MINUTE) + ":");
  String sec = ("" + gcalendar.get(Calendar.SECOND));

then do:

<textFieldName>.setText(hr + min + sec);

that will change the text in the textfield to "HH:MM:SS"

frescaaaaa
  • 45
  • 7