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
There's a getText method or something like that... and there are regex matchers.
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
You might also want to try JFormattedTextField's features: http://www-128.ibm.com/developerworks/java/library/j-mer0625/Mike
And here http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html
i do'nt understand how i can use jformattedtext in my jtextfilether's no method that can add a mask to a jtextfield
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
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
> 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.
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
> 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".
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
i will write the time hardly in the code so is there any method to use?
> 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?
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
> 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?
with new Date() as input it shows the current time
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
> 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?