Home Java Example Java Swing Create a JSpinner Component in Java



Create a JSpinner Component in Java
Posted on: April 14, 2007 at 12:00 AM
In this section, you will learn how to create a JSpinner component of swing.

Create a JSpinner Component in Java

     

In this section, you will learn how to create a JSpinner component of swing. The JSpinner provides the up-down arrow buttons which are used to increase or decrease the numeric value.

This program provides an appropriate JSpinner component on the frame. The following figure shows that:

Swing JSpinner Component

This program have used the following methods or API's components for appropriate:

JSpinnerComp():
This is the constructor of JSpinnerComp class. This constructor used for displaying the JSpinner component on the frame.

JSpinner():
This is the constructor of JSpinner class. It extends form the JComponent class. This is used to create a spinner. It takes the initial value "0" by default.

Here is the code of program:

import javax.swing.*;
import java.awt.*;
import java.util.*;

public class JSpinnerComp{
  public static void main(String[] args) {
  JSpinnerComp h = new JSpinnerComp();
  }

  public JSpinnerComp(){
  JFrame frame = new JFrame("Creating a JSpinner Component");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  JSpinner spinner = new JSpinner();
  frame.add(spinner,BorderLayout.NORTH);
  frame.setSize(100,100);
  frame.setVisible(true);
  }
}

Download this example

Related Tags for Create a JSpinner Component in Java:
javacswingjspidebuttoniostructsedconstvivaluethisidrowbuttonsjsframenumerictoramstructsedessectionuseinasmspinnertrarrowjinneresspiasepijspinnermeprododownwhichssppinincisncreaarconsstrwingvattssrithspinswavstaluctsframprono


More Tutorials from this section

Ask Questions?    Discuss: Create a JSpinner Component in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.