new JFormattedTextField(new DecimalFormat('###,###')) : JFormattedTextField « javax.swing « Java by API






new JFormattedTextField(new DecimalFormat('###,###'))

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

import javax.swing.Box;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.text.MaskFormatter;

public class MainClass {

  public static void main(String[] args) throws Exception {
    Box form = Box.createVerticalBox();
    form.add(new JLabel("Name:"));
    form.add(new JTextField("User Name"));

    form.add(new JLabel("Birthday:"));
    JFormattedTextField birthdayField = new JFormattedTextField(new SimpleDateFormat("MM/dd/yy"));
    birthdayField.setValue(new Date());
    form.add(birthdayField);

    form.add(new JLabel("Age:"));
    form.add(new JFormattedTextField(new Integer(32)));

    form.add(new JLabel("Hairs on Body:"));
    JFormattedTextField hairsField = new JFormattedTextField(new DecimalFormat("###,###"));
    hairsField.setValue(new Integer(100000));
    form.add(hairsField);

    form.add(new JLabel("Phone Number:"));
    JFormattedTextField phoneField = new JFormattedTextField(new MaskFormatter("(###)###-####"));
    phoneField.setValue("(314)888-1234");
    form.add(phoneField);

    JFrame frame = new JFrame("User Information");
    frame.getContentPane().add(form);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
  }
}
           
         
    
  








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 SimpleDateFormat('MM/dd/yy'))
7.JFormattedTextField: addActionListener(ActionListener l)
8.JFormattedTextField: commitEdit()
9.JFormattedTextField: getFormatterFactory()
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