2
我正在嘗試請求專注於第一個用戶名字段,但它並不專注於文本字段。這裏是我的代碼:Java username.requestFocus();不工作在JOptionPane
JTextField username = new JTextField();
JTextField password = new JPasswordField();
JTextField prefix = new JTextField();
username.requestFocus();
Object[] message = {
"Username:", username,
"Password:", password,
"Prefix:", prefix
};
int option = JOptionPane.showConfirmDialog(null, message, "Login", JOptionPane.OK_CANCEL_OPTION);
username.requestFocus();
if (option == JOptionPane.OK_OPTION) {
return ls.login(username.getText(), password.getText(), prefix.getText());
} else {
return false;
}
我能做些什麼來請求用戶名文本字段的重點?
username.requestFocusInWindow();在invokeLater中 – mKorbel