Can a JFormattedTextField be assigned a formatter which has placeholders

53 views Asked by At

I've used the following line of code to only allow users to enter digits inside a JFormattedTextField which collects information on time

final JFormattedTextField periodTextField = new JFormattedTextField();
periodTextField.setFormatterFactory(new DefaultFormatterFactory(createFormatter("##:## - ##:##")));

When running my application the text field will appear as ": - :" by default, but I would like it to appear as "00:00 - 00:00" as default, and editing the text field will only change the values of the 0's nothing else. I've looked at this guide for help on using formatters in java, but it doesn't mention how you can set default values. Is there a simple way to achieve what I need.

0

There are 0 answers