0
我使用JOptionPane
創建了一個密碼字段。當我運行程序時,JOptionPane
出現並且看起來很棒,但是焦點始終轉到確定按鈕。我想要在密碼字段開始焦點。我試過requestFocus()
,requestFocusInWindow()
,但這似乎不起作用。有什麼特別的,我需要去關注密碼領域?在JOptionPane中設置焦點JPasswordField
見下面我的代碼:
JPasswordField pf = new JPasswordField();
pf.requestFocusInWindow();
int okCxl = JOptionPane.showConfirmDialog(null, pf, "ENTER SUPERUSER PASSWORD", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
的可能重複[如何創建時將焦點設置裏面的JOptionPane具體的JTextField?](http://stackoverflow.com/questions/6478394/how-to-set-focus-on-specific-jtextfield-內部-的JOptionPane-時創建的) – Laf