Start New Discussion within our Software Development Community

Hi, i've got a component that displays two JSpinners with a JOptionPane but the JSpinners are stretched across the dialog window. Does anyone know how i can format the JSpinners so they're smaller?

Here's some of the code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;

public class TComponent
    private SpinnerNumberModel spinnerModel1;
    private SpinnerNumberModel spinnerModel2;
    private JSpinner spinner1;
    private JSpinner spinner2;
    private JOptionPane optionPane;
    private JDialog dialog;
    private JFrame frame;
    public TComponent(JFrame frame)
        this.frame = frame;
        spinnerModel1 = new SpinnerNumberModel(5, 1, 30, 1);
        spinnerModel2 = new SpinnerNumberModel(5, 1, 30, 1);
        spinner1 = new JSpinner(spinnerModel1);
        spinner2 = new JSpinner(spinnerModel2);
        Object[] message = {"Spinner 1: ", spinner1,
                             "Spinner 2: ", spinner2};
        Object[] options = {"OK", "Cancel"};
        optionPane = new JOptionPane(message,
                          null, options);

        dialog = optionPane.createDialog(frame, "Spinners");;

    public static void main(String[] args)
        JFrame frame = new JFrame();
        frame.setSize(600, 500);
        frame.setLocation(300, 300);
        TComponent op = new TComponent(frame);
This article has been dead for over six months. Start a new discussion instead.