Reputation: 1
How it will work? If i press the button and the text field is empty it will display a asterisk sign besides the textfiled.
if(txtfname.getText().equals(" ")){
JOptionPane.showMessageDialog(null, "Missing field");
jLabel20.setText("*");
}
Upvotes: 0
Views: 1106
Reputation: 19185
if(txtfname.getText().trim().isEmpty())//Trim removes unnecessary chars is empty checks for emptyness
//show *
Remember trim()
on null
string can generate NullPointerException
so you should also check for null
before.
Upvotes: 4