permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes how to compare values in text box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to compare values in text box" Watch "how to compare values in text box" New topic
Author

how to compare values in text box

Shamsa Aziz
Greenhorn

Joined: Dec 06, 2012
Posts: 11
Salaam!

How do I compare passwords from two text boxes and can generate a popup dialog if both doesn't match?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38020
    
  22
Welcome to the Ranch

I presume you know how to get text from text boxes with their methods? And how to compare the text, which is a String? You will probably find a dialogue the simplest form of popup; try option panes. Note that API link contains a Java Tutorials link, which will probably help, too.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38020
    
  22
By the way: there is a special text component designed for passwords. I can’t remember its name, but it is something like JPasswordField.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Is this a Java or JavaScript question?


luck, db
There are no new questions, but there may be new answers.
Shamsa Aziz
Greenhorn

Joined: Dec 06, 2012
Posts: 11
Thank you campbell

here's how I did

if(!(Password.getPassword().equals(Password2.getPassword())))
{
JOptionPane.showMessageDialog(null, "Not matched");
}
But not working for me
Shamsa Aziz
Greenhorn

Joined: Dec 06, 2012
Posts: 11
Darryl Burke wrote:Is this a Java or JavaScript question?


It's java, I have created a login form in Jfram and want to do a comparison of password and retype password fields. The form should only be submitted if both the fields match
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 459
    
    1
Please check Java docs



You have to pass parentComponent value which in your code is null.


Vinod Tiwari | Twitter
Shamsa Aziz
Greenhorn

Joined: Dec 06, 2012
Posts: 11
Vinod Tiwari wrote:Please check Java docs



You have to pass parentComponent value which in your code is null.



Is that really the problem? I mean solution?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Shamsa Aziz wrote:
Darryl Burke wrote:Is this a Java or JavaScript question?


It's java, I have created a login form in Jfram and want to do a comparison of password and retype password fields. The form should only be submitted if both the fields match


The reason I asked is because Java doesn't have anything called a "text box" -- which you mentioned in your first post.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Shamsa Aziz wrote:
Vinod Tiwari wrote:Please check Java docs



You have to pass parentComponent value which in your code is null.



Is that really the problem? I mean solution?


No, it's not important at all. Shamsa, there is absolutely no problem with passing null as the parentComponent argument to a JOptionPane method.

For your solution, check out the equals(...) methods of java.util.Arrays
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38020
    
  22
Another catch is that when you pass null as the first argument to that JOptionPane method, the dialogue window appears in the centre of the screen, but might be behind other windows on your screen.
Shamsa Aziz
Greenhorn

Joined: Dec 06, 2012
Posts: 11
Hello everyone!

My code is running successfully now so I want to share what I did.

I have converted the password into Strings and then did a comparison.
I did like this

String password= new String(Password.getPassword());
String password2= new String(Password2.getPassword());
If(!(password.equals(password2))
{
.......
}

and it works

Thank you All.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38020
    
  22
well done
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to compare values in text box
 
Similar Threads
JavaFX v Flex
how do I validate a listbox
Compare two text
why is iphone popular ?
Code Craft vs. Effective Java