How to create a Spinner using Java JSpinner class

How to create a Spinner using Java JSpinner class

It's pretty easy to create a Spinner using Java JSpinner class.JSpinner object allows the user to select a particular value from a certain ordered sequence.

How to declare  Java JSpinner class

[class JSpinner extends JComponent implements Accessible
 
 
]

Java JSpinner class constructors

  • JSpinner()-creates spinner with integer as SpinnerNumberModel.Initial value is 0.It has no minimum or maximum.
  • JSpinner(SpinnerModel model)-constructs a specified spinner for a given model

Java JSpinner class methods

  • void addChangeListener(ChangeListener l)-adds a listener to a list that notifies each time a change to model occurs.
  • Object getValue()-returns value of current model.

Example of Java JSpinner class

[
/** * This program creates a simple JSpinner Example 
* * @author Eric 
*/
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
public class JavaJSpinnerExample extends JFrame {
    JavaJSpinnerExample ()
    {
        super("Java JSpinner Example");
        SpinnerModel model=new SpinnerNumberModel(10,0,50,1);
        JSpinner spinner=new JSpinner(model);
        spinner.setBounds(10, 10, 200, 20);
        add(spinner);
        setSize(300,100);
        setLayout(null);
        setVisible(true);
    }
    public static void main(String args[])
    {
        new  JavaJSpinnerExample ();
    }

}
]

Java JSpinner Example with ChangeListener

[
/** * This program creates a simple JSpinner Example 
* * @author Eric 
*/
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.JLabel;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class JavaJSpinnerExample extends JFrame {
    JavaJSpinnerExample ()
    {
        super("Java JSpinner Example");
        SpinnerModel model=new SpinnerNumberModel(10,0,50,1);
        JSpinner spinner=new JSpinner(model);
        spinner.setBounds(10, 10, 200, 20);

        final JLabel label = new JLabel();
        label.setBounds(10, 40, 200, 30);
        add(label);
        spinner.addChangeListener(new ChangeListener()
        {
            public void stateChanged(ChangeEvent evt)
            {
                label.setText("Value= "+ ((JSpinner)evt.getSource()).getValue());
            }

        });
        add(spinner);

        setSize(300,200);
        setLayout(null);
        setVisible(true);
    }
    public static void main(String args[])
    {
        new  JavaJSpinnerExample ();
    }

}
]

Related Tutorials

COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: How to create a Spinner using Java JSpinner class
How to create a Spinner using Java JSpinner class
How to create a Spinner using Java JSpinner class
https://4.bp.blogspot.com/-MNQVDoxdY4U/WODhTQEp2GI/AAAAAAAAHZg/IYxa_-pSO1suz29dt1qSjpxX7u1Tb1-jQCLcB/s320/java-jspinner-example.PNG
https://4.bp.blogspot.com/-MNQVDoxdY4U/WODhTQEp2GI/AAAAAAAAHZg/IYxa_-pSO1suz29dt1qSjpxX7u1Tb1-jQCLcB/s72-c/java-jspinner-example.PNG
Java Codes
http://www.download-all.net/2017/04/how-to-create-spinner-using-java.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/04/how-to-create-spinner-using-java.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy