你好我正在使用JPasswordField
當我想讀它時,getPassword
沒有問題,但我正在做的是當沒有設置密碼時它顯示一個InputDialog
你可以輸入密碼和那麼它應該將密碼設置爲JPasswordField
,但是當我使用setText
時,它不會設置它,並且不存在方法setPassword()
。所以我的問題是我如何設置密碼到JPasswordField
?JPasswordField如何設置密碼
String password = "";
JPasswordField passwordField = new JPasswordField();
passwordField.setEchoChar('*');
Object[] obj = {"Bitte ihr PAsswort eingeben:\n\n", passwordField};
Object stringArray[] = {"OK","Cancel"};
if (JOptionPane.showOptionDialog(null, obj, "Passwort", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, stringArray, obj) == JOptionPane.WARNING_MESSAGE)
{
password = new String(passwordField.getPassword());
}
txtFtpUser.setText(username);
panel_1.remove(txtFtpPassword);
txtFtpPassword = new JPasswordField(password);
txtFtpPassword.setBounds(10, 113, 206, 23);
panel_1.add(txtFtpPassword);
http://docs.oracle.com/javase/7/docs/api/javax/swing/JPasswordField.html#JPasswordField%28java.lang.String%29 – KrHubert
沒有一些代碼片段,很難告訴你什麼是錯的。 – Flawyte
我做了txtPassword = new JPasswordField(「PASSWORD」);但它仍然沒有工作。我也試過panel.remove(txtPassword);定義它新的,setBounds並添加它與panel.add(txtPassword)再次它也沒有工作。 – alexj