• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Java » Swing » JSpinner Java Swing Example
Next →
← Prev

JSpinner Java Swing Example

By Dinesh Thakur

JSpinner: Selects a value from a range of possible options to Like the drop-down lists, but show no such list. values changed by pressing the scroll buttons. You can also enter a  value directly.

import java.awt.BorderLayout; 
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class JavaExampleSpinner extends JFrame implements ChangeListener
  {
    JLabel LblQty;
    JLabel LblDt;
    JSpinner Spnr;
    JSpinner DateSpnr;
    JavaExampleSpinner(String Tytl)
     {
       setTitle(Tytl);
       setSize(500,200);
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       Container Cntnr=getContentPane();
       Cntnr.setLayout(new GridLayout(2,1));
       JPanel Pnl=new JPanel();
       Pnl.setLayout(new GridLayout(2,2));
       Pnl.setBorder(BorderFactory.createTitledBorder("Sale Entry"));
       SpinnerNumberModel SpnrNmbrMdl=new SpinnerNumberModel(10,1,100,1);
       Spnr=new JSpinner(SpnrNmbrMdl);
       Spnr.addChangeListener(this);
       Pnl.add(new JLabel("Select Quantity to Be Sold:"));
       Pnl.add(Spnr);
       Date Dt=new Date();
       SpinnerDateModel SpnrDtMdl=new SpinnerDateModel(Dt,null,null,Calendar.DATE);
       DateSpnr=new JSpinner(SpnrDtMdl);
       DateSpnr.setEditor(new JSpinner.DateEditor(DateSpnr,"dd:MM:yyyy"));
       DateSpnr.addChangeListener(this);
       Pnl.add(new JLabel("Select Sale Date:"));
       Pnl.add(DateSpnr);
       Cntnr.add(Pnl,BorderLayout.CENTER);
       JPanel Panl=new JPanel();
       Panl.setLayout(new FlowLayout());
       LblQty=new JLabel();
       LblQty.setForeground(Color.GREEN);
       LblDt=new JLabel();
       LblDt.setForeground(Color.RED);
       Panl.add(LblQty);
       Panl.add(LblDt);
       Panl.setBorder(BorderFactory.createTitledBorder("Information"));
       Cntnr.add(Panl); 
       setVisible(true);
     }
       public void stateChanged(ChangeEvent ee)
        {
           JSpinner JSpnr=(JSpinner)ee.getSource();
           try
            {
               JSpnr.commitEdit();
            }
              catch(ParseException PrsEx){}
              if(JSpnr==Spnr)
              LblQty.setText("Quantity:"+JSpnr.getValue().toString());
              else if(JSpnr==DateSpnr)
              LblDt.setText("Date:"+JSpnr.getValue().toString());
        }
              public static void main(String[] aa)
            {
                   new JavaExampleSpinner("Example Date Spinner In Java");
                }
 }

JSpinner

You’ll also like:

  1. JList in Java Swing Example
  2. SpringLayout in Java Swing Example
  3. FocusListener in Java Swing Example
  4. CheckerBoard Java Swing Example
  5. Gradient in Java Swing Example
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

SQL Tutorials

SQL Tutorials

  • SQL - Home
  • SQL - Select
  • SQL - Create
  • SQL - View
  • SQL - Sub Queries
  • SQL - Update
  • SQL - Delete
  • SQL - Order By
  • SQL - Select Distinct
  • SQL - Group By
  • SQL - Where Clause
  • SQL - Select Into
  • SQL - Insert Into
  • SQL - Sequence
  • SQL - Constraints
  • SQL - Alter
  • SQL - Date
  • SQL - Foreign Key
  • SQL - Like Operator
  • SQL - CHECK Constraint
  • SQL - Exists Operator
  • SQL - Drop Table
  • SQL - Alias Syntax
  • SQL - Primary Key
  • SQL - Not Null
  • SQL - Union Operator
  • SQL - Unique Constraint
  • SQL - Between Operator
  • SQL - Having Clause
  • SQL - Isnull() Function
  • SQL - IN Operator
  • SQL - Default Constraint
  • SQL - Minus Operator
  • SQL - Intersect Operator
  • SQL - Triggers
  • SQL - Cursors

Advanced SQL

  • SQL - Joins
  • SQL - Index
  • SQL - Self Join
  • SQL - Outer Join
  • SQL - Join Types
  • SQL - Cross Join
  • SQL - Left Outer Join
  • SQL - Right Join
  • SQL - Drop Index
  • SQL - Inner Join
  • SQL - Datediff() Function
  • SQL - NVL Function
  • SQL - Decode Function
  • SQL - Datepart() Function
  • SQL - Count Function
  • SQL - Getdate() Function
  • SQL - Cast() Function
  • SQL - Round() Function

Other Links

  • SQL - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW