0

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("");
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • You have two declarations of the variable `jpwf`: `JPasswordField jpwf` and then `String jpwf`. That's not possible – Guillaume Polet Apr 15 '13 at 09:34
  • You should not be using `JPassWordField#getText` (see http://stackoverflow.com/q/983964/1076463 and http://stackoverflow.com/q/10443308/1076463) – Robin Apr 15 '13 at 09:55

2 Answers2

2

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().

Guillaume Polet
  • 47,259
  • 4
  • 83
  • 117
  • sorry it got written wrong by mistake, I am calling jpwf.setText(""); –  Apr 15 '13 at 09:29
  • @user1782870 update your post to reflect exactly what you have and where the error occurs. – Guillaume Polet Apr 15 '13 at 09:30
  • JTextField jtf=new JTextField(8); JPasswordField jpwf=new JPasswordField(8); String value= jtf.getText(); String jpwf= jpwfName.getText(); jtfName.setText(""); –  Apr 15 '13 at 09:31
  • and the callin function on the password field is jpwf.setText(""); –  Apr 15 '13 at 09:32
  • @user1782870 Edit directly your post instead of posting comments. As I mentionned in my answer, you declare twice the variable `jpwf`. Read my answer again! – Guillaume Polet Apr 15 '13 at 09:32
0

u can user this code

    jpwf.setText("");

in the line of u typed like

  jtfName.setText("");
karthi
  • 1,059
  • 3
  • 10
  • 21