I Created a Frame and a customised dialog box. if some of the fields in dialog box is empty i am throwing a JOptionpane dialog with a error message . The probelm is while throwing the error dilaog the focus is on the OK button but still it doesnt closing while i'm pressing the space bar.