Example usage for javax.swing JSpinner JSpinner

List of usage examples for javax.swing JSpinner JSpinner

Introduction

In this page you can find the example usage for javax.swing JSpinner JSpinner.

Prototype

public JSpinner(SpinnerModel model) 

Source Link

Document

Constructs a spinner for the given model.

Usage

From source file:Main.java

public Main() {
    super("Month Spinner");
    setSize(200, 100);//  w  ww  .  ja  v  a 2s. co m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4));

    c.add(new JLabel("Expiration Date:"));
    Date today = new Date();
    JSpinner s = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH));
    JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy");
    s.setEditor(de);
    c.add(s);

    setVisible(true);

    System.out.println(s.getPreviousValue());
}

From source file:MainClass.java

public MainClass() {
    super("Month Spinner");
    setSize(200, 100);/*w w  w .j av  a  2 s.  c  om*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4));

    c.add(new JLabel("Expiration Date:"));
    Date today = new Date();
    JSpinner s = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH));
    JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy");
    s.setEditor(de);
    c.add(s);

    setVisible(true);
}

From source file:Main.java

public Main() {
    super("Month Spinner");
    setSize(200, 100);/* ww w. j  a  v a2 s  .c o  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4));

    c.add(new JLabel("Expiration Date:"));
    Date today = new Date();
    JSpinner s = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH));
    JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy");
    s.setEditor(de);
    c.add(s);

    setVisible(true);

    try {
        s.commitEdit();
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    JSpinner m_numberSpinner;//from   www. j  a v  a 2  s  .  c o  m
    SpinnerNumberModel m_numberSpinnerModel;
    Double current = new Double(5.50);
    Double min = new Double(0.00);
    Double max = new Double(10.00);
    Double step = new Double(0.25);
    m_numberSpinnerModel = new SpinnerNumberModel(current, min, max, step);
    m_numberSpinner = new JSpinner(m_numberSpinnerModel);
    add(m_numberSpinner);
}

From source file:Main.java

public Main() {
    setSize(200, 100);//  ww  w. j  a v a  2 s  .  c  om
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4));

    c.add(new JLabel("Expiration Date:"));
    Date today = new Date();
    // Start the spinner today, but don't set a min or max date
    // The increment should be a month
    JSpinner s = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH));
    JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy");
    s.setEditor(de);
    c.add(s);

    setVisible(true);
}

From source file:Main.java

public Main() {
    JSpinner m_listSpinner;//from   w  w  w.j av  a 2  s. co m
    SpinnerListModel m_listSpinnerModel;
    List<String> sequence = new ArrayList<String>();

    sequence.add(new String("I - First"));
    sequence.add(new String("II - Second"));
    sequence.add(new String("III - Third"));
    sequence.add(new String("IV - Fourth"));
    sequence.add(new String("V - Fifth"));
    sequence.add(new String("VI - Sixth"));

    m_listSpinnerModel = new SpinnerListModel(sequence);

    m_listSpinner = new JSpinner(m_listSpinnerModel);
    add(m_listSpinner);
}

From source file:Main.java

public Main() {
    super("JSpinner Icon Test");
    setSize(300, 80);/*from  ww w  .  j a  va2s .  co  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new GridLayout(0, 2));

    Icon nums[] = new Icon[] { new ImageIcon("1.gif"), new ImageIcon("2.gif"), new ImageIcon("3.gif"),
            new ImageIcon("4.gif"), new ImageIcon("5.gif"), new ImageIcon("6.gif") };
    JSpinner s1 = new JSpinner(new SpinnerListModel(nums));
    s1.setEditor(new IconEditor(s1));

    System.out.println(s1.getEditor());

    c.add(new JLabel(" Icon Spinner"));
    c.add(s1);

    setVisible(true);
}

From source file:MainClass.java

public MainClass() {
    super("JSpinner Icon Test");
    setSize(300, 80);/*from   w ww .j a v a 2s.c  o m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new GridLayout(0, 2));

    Icon nums[] = new Icon[] { new ImageIcon("1.gif"), new ImageIcon("2.gif"), new ImageIcon("3.gif"),
            new ImageIcon("4.gif"), new ImageIcon("5.gif"), new ImageIcon("6.gif") };
    JSpinner s1 = new JSpinner(new SpinnerListModel(nums));
    s1.setEditor(new IconEditor(s1));
    c.add(new JLabel(" Icon Spinner"));
    c.add(s1);

    setVisible(true);
}

From source file:Main.java

public Main() {
    JSpinner m_dateSpinner;// w  ww.  j  a v a  2 s.  c  o m
    SpinnerDateModel m_dateSpinnerModel;
    Calendar rightNow = Calendar.getInstance();

    Date current = rightNow.getTime();

    rightNow.set(Calendar.HOUR_OF_DAY, -24);
    Date start = rightNow.getTime();
    rightNow.set(Calendar.HOUR_OF_DAY, 48);
    Date end = rightNow.getTime();

    int step = Calendar.HOUR_OF_DAY;
    m_dateSpinnerModel = new SpinnerDateModel(current, start, end, step);
    m_dateSpinner = new JSpinner(m_dateSpinnerModel);
    add(m_dateSpinner);
}

From source file:Main.java

public Main() {
    MyCanvas thingy = new MyCanvas();
    setLayout(new BorderLayout());
    JPanel panel = new JPanel();
    panel.add(thingy);//from   w  w w  .j a  v  a2  s.  com
    JScrollPane scroll = new JScrollPane();
    scroll.setViewportView(panel);
    add(scroll, BorderLayout.CENTER);
    SpinnerNumberModel spmodel = new SpinnerNumberModel(thingy.getThingySize(), 10.0, 2000.0, 10.0);
    spmodel.addChangeListener(e -> thingy.setThingySize((Double) spmodel.getNumber()));
    add(new JSpinner(spmodel), BorderLayout.NORTH);
}