[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using getText() with a JTextField component?
When you use "==" on objects, you are comparing whether they point to the
same object or not. Use the equals() from class String to compare Strings.
Jason R. Kretzer
----- Original Message -----
From: "D. Michael Nelson" <email@example.com>
Cc: "Suhas Kelkar" <firstname.lastname@example.org>
Sent: Wednesday, August 01, 2001 1:41 AM
Subject: Using getText() with a JTextField component?
> I am using the getText() JTextComponent method to retrieve a string form a
> JTextField component. The problem that I am getting is the string is
> returned back, but it does pass a comparsion check when I compared it to
> another string:
> file://ie lets say the string entered in the text field is "Mike"
> String sName = m_nameTF.getText().trim();
> file://The following line works - prints "Mike
> file://This condition fails
> if (sName == "Mike")
> Any suggestions?