NumberFormat: getInstance() : NumberFormat « java.text « Java by API






NumberFormat: getInstance()

 
import java.awt.FlowLayout;
import java.awt.Font;
import java.text.Format;
import java.text.NumberFormat;
import java.util.Locale;

import javax.swing.BoxLayout;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class MainClass {
  public static void main(String args[]) throws Exception {

    JFrame frame = new JFrame("Number Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Font font = new Font("SansSerif", Font.BOLD, 16);

    JLabel label;
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    Format general = NumberFormat.getInstance();
    label = new JLabel("General/Instance:");
    input = new JFormattedTextField(general);
    input.setValue(2424.50);
    input.setColumns(20);
    input.setFont(font);
    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);
    frame.add(panel);

    frame.pack();
    frame.setVisible(true);
  }
}
           
         
  








Related examples in the same category

1.NumberFormat: format(Object obj)
2.NumberFormat.getCurrencyInstance();
3.NumberFormat: getCurrencyInstance(Locale.UK)
4.NumberFormat: getNumberInstance()
5.NumberFormat: getNumberInstance(Locale.FRENCH)
6.NumberFormat: getIntegerInstance(Locale.ITALIAN)
7.NumberFormat: getNumberInstance(Locale inLocale)
8.NumberFormat: getPercentInstance(Locale inLocale)
9.NumberFormat: parse(String source)
10.NumberFormat.setMaximumFractionDigits(int newValue)
11.NumberFormat: setMinimumFractionDigits(int newValue)
12.NumberFormat: setMinimumIntegerDigits(int newValue)
13.NumberFormat: setParseIntegerOnly(boolean value)