Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane and FocusListener  RSS feed

 
Ameet Choughule
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to show a warning so that one JTextField should not be left blank. I used the focusLost method of focuslistener. In this method i used JOptionPane.showMessageDialog(this, "do not leave blank", "Blank", JOptionPane.INFORMATION_MESSAGE). I got this message box as I leave that text field (when it is blank). However, I do not know how to get rid of this message. Kindly advice. Also note that focusLost() method is void and cannot return any integers.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, it works for me. I'm using as follows :
if(textName.equals("myTF")){
int numDays2 = (new Integer(myTF.getText())).intValue();
if (numDays2 <= 0){
JOptionPane.showMessageDialog(this, "Minimum # of scheduled hours/day cannot be less or equal to 0.", "Error Message ", JOptionPane.OK_OPTION);
return;
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!