Setting component focus in JOptionPane.showOptionDialog()
问题 In order to have custom button captions in an input dialog, I created the following code: String key = null; JTextField txtKey = new JTextField(); int answerKey = JOptionPane.showOptionDialog(this, new Object[] {pleaseEnterTheKey, txtKey}, decryptionKey, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] {okCaption, cancelCaption}, okCaption); if (answerKey == JOptionPane.OK_OPTION && txtKey.getText() != null) { key = txtKey.getText(); } How can I move the focus