JFormattedTextField: getFormatterFactory() : JFormattedTextField « javax.swing « Java by API






JFormattedTextField: getFormatterFactory()

  


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.swing.JFormattedTextField;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.text.DateFormatter;
import javax.swing.text.DefaultFormatterFactory;

public class Main {
  public static void main(String[] argv) throws Exception {
    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.HOUR_OF_DAY, 13); // 1pm

    SpinnerDateModel dateModel = new SpinnerDateModel(calendar.getTime(), null,
        null, Calendar.HOUR_OF_DAY);
    JSpinner spinner = new JSpinner(dateModel);

    JFormattedTextField tf = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
    DefaultFormatterFactory factory = (DefaultFormatterFactory) tf.getFormatterFactory();
    DateFormatter formatter = (DateFormatter) factory.getDefaultFormatter();

    // Change the date format to only show the hours
    formatter.setFormat(new SimpleDateFormat("hh:00 a"));
    //formatter.setFormat(new SimpleDateFormat("HH:00 a"));
  }
}

   
    
  








Related examples in the same category

1.new JFormattedTextField(Format format)
2.new JFormattedTextField(Formatter formatter)
3.new JFormattedTextField(AbstractFormatterFactory factory, Object currentValue)
4.new JFormattedTextField(Object value)
5.new JFormattedTextField(new MaskFormatter('(###)###-####'))
6.new JFormattedTextField(new DecimalFormat('###,###'))
7.new JFormattedTextField(new SimpleDateFormat('MM/dd/yy'))
8.JFormattedTextField: addActionListener(ActionListener l)
9.JFormattedTextField: commitEdit()
10.JFormattedTextField: getValue()
11.JFormattedTextField: isEditValid()
12.JFormattedTextField: setColumns(int columns)
13.JFormattedTextField: setFont(Font f)
14.JFormattedTextField: setFormatterFactory(AbstractFormatterFactory tf)
15.JFormattedTextField: setInputVerifier(InputVerifier inputVerifier)
16.JFormattedTextField: setValue(Object value)
17.JFormattedTextField deals with URL