简体   繁体   中英

how to empty the password field value(String) in java using swing

I have Textfield and password field.I am able to get the string written in the textfield and password field but not able to setting the text of password field empty.

The error comes "The method setText(String) is undefined for type string"

JTextField jtf=new JTextField(8);
JPasswordField jpwf=new JPasswordField(8);
String value= jtf.getText();
String jpwf= jpwfName.getText();
jtfName.setText("");
**Error on this line**//jpwf.setText("");

You are not calling the setText() method on the correct variable. Use

jpwf.setText("");

instead of

pwd.setText("");

There is also another problem before that, you declare twice the variable jpwf (once with JPasswordField and once with String ). Maybe it's only a typo.

The error you get says that you have a variable jpwf of the type String on which there is no method named setText() .

u can user this code

    jpwf.setText("");

in the line of u typed like

  jtfName.setText("");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM