我正在尝试将 JSpinner 放入 JOptionPane 中,如下所示,
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);
这可行,但唯一的问题是 JSpinner 填充对话框的宽度,而不管我设置的大小。我也尝试过使用 setPreferredSize() 。我该如何解决?