I want to be able to pick up when nothing has been entered into a JTextField. I have tried checking for a null string, but this does not work. Any ideas??
Well, one would be the following: textField.getText().trim().lenght(); //some where in your code
The other would be to add a keyListener to the textField and check for the following when a key has been Released. <pre> public void keyReleased(KeyEvent e) {
if (textField.getText().trim().length() == 0) { //text is empty } else if (textField.getText().trim().length() > 0) { //It has Text!! } }
You can do it a couple of ways. if (MyTextArea.getText().compareTo("") == 0) { //There is no text here } or you can do String myText = myTextArea.getText(); and then compare myText the same way as above.