1
使用JOptionPane.showConfirmDialog多輸入:JOptionPane.showConfirmDialog多輸入月初返回時,返回鍵擊
int result = JOptionPane.showConfirmDialog(null, panel,
prompt, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
面板是建立在以下方式:
JTextField percentField = new JTextField(5);
JComboBox cb = new JComboBox(movingAveragesList);
JPanel myPanel = new JPanel();
myPanel.add(new JLabel("Enter %:"));
myPanel.add(percentField);
myPanel.add(Box.createHorizontalStrut(5)); // a spacer
myPanel.add(new JLabel("Select MA:"));
myPanel.add(cb);
當用戶進入%字段和命中返回,代碼返回沒有完成組合框選擇。返回鍵==單擊確定按鈕。無論如何要解決這個問題,所以確定按鈕需要打回來之前?
我喜歡第三個選項,會試試看。謝謝! – wsteve
@wsteve:不客氣。如果您不想選擇下一個組件,您也可以將操作偵聽器的主體留空。 –