I’m trying to put a JSpinner in a JOptionPane as follows,
SpinnerModel saModel = new SpinnerNumberModel(11, 1, 36, 1);
JSpinner saSpinner = new JSpinner(saModel);
Dimension d = saSpinner.getSize();
d.width = 20;
saSpinner.setSize(d);
Object[] message = { "Choose the key number for sa.", saSpinner };
JOptionPane optionPane = new JOptionPane(message,
JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
JDialog dialog = optionPane.createDialog(frame, "Change Sa Key");
dialog.setVisible(true);
This works, but the only issue is that the JSpinner fills the width of the Dialog regardless of the size I set. I’ve tried using setPreferredSize() as well. How do I fix this?
Why not instead just put it in a JPanel?
Though myself, I don’t know that I’d create a JDialog for this, but instead would simply display the
JOptionPane.showConfirmDialog(...)method: