JSpinner in JOptionPane?

I need to put a JSpinner in a JOptionPane. Here is what I've tried:

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

    public static void main(String[] args) {
        SpinnerNumberModel sModel = new SpinnerNumberModel(0, 0, 30, 1);
        JSpinner spinner = new JSpinner(sModel);
        JOptionPane.showInputDialog(spinner);
    }

Which results in:

How do I remove the textbox?

Answers


You have to use showMessageDialog.

SpinnerNumberModel sModel = new SpinnerNumberModel(0, 0, 30, 1);
JSpinner spinner = new JSpinner(sModel);
JOptionPane.showMessageDialog(null, spinner);

For still having a cancel button, use:

int option = JOptionPane.showOptionDialog(null, spinner, "Enter valid number", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
if (option == JOptionPane.CANCEL_OPTION)
{
    // user hit cancel
} else if (option == JOptionPane.OK_OPTION)
{
    // user entered a number
}

Here is a screenshot on OS X:


Need Your Help

Changing rich faces extendeddatatable height from a command button Click

javascript css jsf richfaces facelets

I am new to RichFaces and Facelets. I am trying to increase the height of an ExtendedDataTable defined in my project. I have a command button in the xhtml called "Expand". When I click on "Expand" ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.