Java Question: I have editable JTextFields in my code. The JTextField is initialized with a value of "" using .setText(). I have code to check the value of the JTextField to avoid a null value, i.e. the user has to change it but it would appear to not be working. I am going to paste the chek part to see if it's something obvious. If needed I can attach the whole thing: if (empNameText.getText() == null) { setTextRed(empNameLabel); goodData = false; System.out.println("True"); } else { System.out.println("False"); } Keep in mind I have the System.out in the
The system.out is included for troubleshooting purposes.
Allow me to kick myself. Since I am using a string I need to use .equals or I am looking at the memory address of the variable. Found my answer here: http://www.codingforums.com/archive/index.php/t-96034.html
Yeah, you're gonna want to use the .equals method of the string class for this, as apposed to the ==.
I got confused since I was working with a single character string. While I knew I was dealing with a string my brain kept screaming char. It's always the easy problems that kick your retrice:)
Well really an empty string, but I kept thinking char.
Haha, quite alright.
Join our real-time social learning platform and learn together with your friends!