How to make jtextfield with fixed date format?

I am having trouble creating a fixed date format using JTextField. Is there a way to JTextFieldhave a fixed date format?

+5
source share
5 answers

You can use JFormattedTextField with SimpleDateFormat

DateFormat format = new SimpleDateFormat("your_format");
JFormattedTextField dateTextField = new JFormattedTextField(format);
+6
source

You should take a look at

To start...

+2
source

Swing, JFormattedTextField JFrame. formatterFactory. " " "". .

enter image description here

+1

Netbeans: JDateChooser, jtext JDateChooser: (1) , JDateChooser, , : yyyy-MM-dd; (2) "jtextfield.setFocusable(false)", ,

enter image description here

enter image description here

enter image description here enter image description here

0

, JFormatedTextField.

, :

package your_package;

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class.....{

private String getdate(){
      DateFormat format = new SimpleDateFormat("MM/DD/YYYY"); //display your format.
      Date date = new Date();//puts the date in variable.
      return dateformat.format(date); //returns the format to the date variable.
}

public your_app{
     .....
     String date = new getdate();
     txtDate.setvalue(date);
}
}

Hope this gives you an idea and helps ... :)

-2
source

All Articles