Java JSpinner.NumberEditor with custom format

Description

Java JSpinner.NumberEditor with custom format

import java.awt.FlowLayout;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;

public class Main extends JFrame {
   public Main() {
      super("java2s.com");

      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setLayout(new FlowLayout());


      SpinnerModel model = new SpinnerNumberModel(50, 0, 100, .25);
      JSpinner spinner = new JSpinner(model);
      JComponent editor = new JSpinner.NumberEditor(spinner, "#,##0.###");
      spinner.setEditor(editor);/*  www.jav  a2 s.  c  o  m*/
      
      getContentPane().add(spinner);
   }

   public static void main(String[] args) {
      Main frame = new Main();
      frame.pack();
      frame.setVisible(true);
   }
}



PreviousNext

Related