JSpinner with an editor object to display the current value - Java Swing

Java examples for Swing:JSpinner

Introduction

JSpinner has the following three static inner classes to display three different kinds of ordered lists:

  • JSpinner.NumberEditor
  • JSpinner.DateEditor
  • JSpinner.ListEditor

Set the number format to "00"

import javax.swing.JSpinner;

public class Main {

  public static void main(String[] args) {

    JSpinner listSpinner = new JSpinner();
    JSpinner.NumberEditor nEditor = new JSpinner.NumberEditor(listSpinner, "00");
    listSpinner.setEditor(nEditor);
  }
}

Set the date format to mm/dd/yyyy

import javax.swing.JSpinner;

public class Main {

  public static void main(String[] args) {

    JSpinner listSpinner = new JSpinner();
    JSpinner.DateEditor dEditor = new JSpinner.DateEditor(listSpinner, "mm/dd/yyyy");
    listSpinner.setEditor(dEditor);
  }
}

Related Tutorials