------------Edit---------------
Question:I have written a JTextField which has a Popup.This popup is an undecorated JFrame.Since the codes has already written by other people,Now I want to implements follow:
1.When the popup lost focus, close the popup.
2.When use clicked on JTextField, if popup is open,close the popup ,else open the popup.
How to implement this?
Following is my attempt,but there is a conflict on it.
Firstly, I have a JTextField with MouseListener using to trigger a JFrame Popup.
public void mousePressed(MouseEvent arg0) {
if (TextField.this.isEnabled() && !popup.isVisible() && TextField.this.isEditable())
open();
else if (popup.isVisible()) {
popup.setVisible(false);
}
}
I add the windowfocuslistener to the JFrame(popup) to ensure it can be close when focus lost.like follow:
popup.addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowLostFocus(WindowEvent e) {
popup.setVisible(false);
}
}
So the problem came,when I click the JTextField firstly, it open the Date popup,when I clicked the JTextField again, it will first call windowlostfocus to setvisible(false).then mouselisten, will open the Date Popup. This is not my thought, I want to close the popup when click again. Anyone has idea to avoid this? Thanks for your help.