I am currently working on an application and I have a certain requirement for my interface: A time input.
I need my controls to accept 12hrs to 24hrs input using JFormattedTextField and found this:
MaskFormatter mask = new MaskFormatter("##:##");
mask.setPlaceHolderCharacter('0');
Now I created a class that extends to a JFormattedTextField
public class JayTimeInput extends JFormattedTextField{....
now I peeked inside JFormattedTextField's source and found something like this:
public JFormattedTextField(Object mask){...
my question is: How do I create my JayTimeInput class that automatically has a mask formatter? I tried declaring it in my constructor but I am not sure about this:
public JayTimeInput(){
try{
MaskFormatter mask = new MaskFormatter("##:##");
mask.setPlaceHolderCharacter('0');
new JFormattedTextField(mask);
}catch(Exception e){e.printStackTrace()}
}
Ive seen examples on how to use MaskFormatter and the only way I found was by declaring it like this:
MaskFormatter mask = new MaskFormatter("##:##");
mask.setPlaceHolderCharacter('0');
JFormattedTextField jformat = new JFormattedTextField(mask);
Im not sure if my actionlistener was correctly done but I need this to work first.
anyone help me out? im still new in creating my own controls by extending existing swings.
UPDATE:
I was looking at the wrong way of customizing my JFormattedTextField. I Should've used FormatFactory. Answer code has been posted for anyone who needs it.