How to check if JPassword field is null

后端 未结 1 654
失恋的感觉
失恋的感觉 2021-01-22 17:09

I want to check the username and password in Swing.

The check works for username, but it doesn\'t work for JPaswordfield. I am posting the related code:



        
相关标签:
1条回答
  • 2021-01-22 17:34

    Very simple get the text using JPasswordField#getPassword() which returns a char[] of the text, then simply get the length of the array and check if it is equal to 0:

    JPasswordField jpf...
    
    if(jpf.getPassword().length == 0) {
        // it is empty
    }else {
       // it is not empty
    }
    
    0 讨论(0)
提交回复
热议问题