give a precise format to a jtextfield

helloi want to a oblige the user to type a precise format in the jtextfield like(dd-mm-yy) can someone help methanks
[137 byte] By [zmerlicnia] at [2007-10-2 8:42:09]
# 1
There's a getText method or something like that... and there are regex matchers.
CeciNEstPasUnProgrammeura at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 2
I believe you would have kept a button for submitting..write ur code (in Action event of submit button) to check for the valid format in the text field.If it is not the valid one, give him a JOptionPane's Warning message to tell him the proper format.Pradhip
Pradhipa at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 3
You might also want to try JFormattedTextField's features: http://www-128.ibm.com/developerworks/java/library/j-mer0625/Mike
bellyrippera at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 4
And here http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html
pbrockway2a at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 5
i do'nt understand how i can use jformattedtext in my jtextfilether's no method that can add a mask to a jtextfield
zmerlicnia at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 6
i'am using eclipse(plugin visual editor)and there is no object named jformattedtext so how i can insert it in my jtextfield?thanks for help
zmerlicnia at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 7

A JFormattedTextField is a JTextField.

So where had written something like:private JTextField myTF;

You change it toprivate JFormattedTextField myTF;

Now you are free to use the "extra" methods of JFormattedTextField

like isEditValid()

The API also gives an example of this classes use to verify input.

Here: http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFormattedTextField.html

pbrockway2a at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 8
> i'am using eclipse(plugin visual editor)Throw it away and learn how to create UIs manually. Because you'd already be done setting up the JFormattedTextField if you weren't using a GUI editor, and would know how to do what you want without one, too.
CeciNEstPasUnProgrammeura at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 9

i have wrote this code

TF_EndPM = new JFormattedTextField(new SimpleDateFormat("hh:mm:ss"));

TF_EndPM.setBounds(new java.awt.Rectangle(210,114,74,22));

TF_EndPM.setValue(new Date());

it works goode but i dont know how to display a choisen time like 12:11:15

can some one help me

thanks

zmerlicnia at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 10
> it works goode but i dont know how to display a choisen time like 12:11:15My guess would be "by supplying the correct date object, maybe from a Calendar".
CeciNEstPasUnProgrammeura at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 11
i want to display a time not a dateand it is only for show the user will after shoose his time can't i display any time i want like 12:10:09
zmerlicnia at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 12
i will write the time hardly in the code so is there any method to use?
zmerlicnia at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 13
> i want to display a time not a dateWhere's the difference?> and it is only for show the user will after shoose> his time > can't i display any time i want like 12:10:09I'm sure you can. What does your code do?
CeciNEstPasUnProgrammeura at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 14

it's only a fonction that display when i open the frame the choosed hours.

private JFormattedTextField getTF_EndPM() {

if (TF_EndPM == null) {

TF_EndPM = new JFormattedTextField(new SimpleDateFormat("hh:mm:ss"));

TF_EndPM.setBounds(new java.awt.Rectangle(210,114,74,22));

TF_EndPM.setValue(new Date());

}

return TF_EndPM;

}

and i want to display the value 18:00:00

thanks for help

zmerlicnia at 2007-7-16 22:44:19 > top of Java-index,Java Essentials,Java Programming...
# 15
> it's only a fonction that display when i open the> frame the choosed hours.I meant what does your text field show, with new Date() as input?
CeciNEstPasUnProgrammeura at 2007-7-20 19:50:50 > top of Java-index,Java Essentials,Java Programming...
# 16
with new Date() as input it shows the current time
zmerlicnia at 2007-7-20 19:50:50 > top of Java-index,Java Essentials,Java Programming...
# 17

Having tough time, Rene?

Dear zmerlicni, please, do stop for a while, take a pencil, a sheet of paper, log off from the forum, put aside the keyboard and think a little. What are the tools you need? You have them all - JFormattedTextField, SimpleDateFormat, Date and Calendar. Now think what you have to accomplish and break it to sequence of actions done using these tools and in no time you will have the solution.

Mike

bellyrippera at 2007-7-20 19:50:50 > top of Java-index,Java Essentials,Java Programming...
# 18
> with new Date() as input it shows the current timeWhat do you think it would display if you don't use the current time, but 12:00:13 or whatever it was?
CeciNEstPasUnProgrammeura at 2007-7-20 19:50:50 > top of Java-index,Java Essentials,Java Programming...