I just try using MouseMotionListener, and it doesn't work , it only work
inside JFrame . I tried a little trick and I thing this techniques can solve
your problem too ...
You can use WindowFocus event, when the focus was lost, It always send
windowLostFocus ...
I don;t know why requestfocus() doesn't work with frame, so I use
JFrame.show() to 'refresh' & to gain the focus again.
If you don;t want someone to close the frame, just set
JFrame.setDefaultCloseOperation with JFrame Do Nothing On Close.
in JFrame constructor add :
////////////////////////////////////////////////////////////////////////////////\
////////////////
WindowFocusListener listen = new WindowFocusListener()
{
public void windowLostFocus(WindowEvent e) {
System.out.println("Window Focus Listener : focus lost");
// requestFocus();
setLocation(200,300);
show();
}
public void windowGainedFocus(WindowEvent e) {
// do nothing
System.out.println("window focus listener : gain focus ");
}
};
addWindowFocusListener(listen);
////////////////////////////////////////////////////////////////////////////////\
///////////
good luck & I hope this is usefull for you project .
ps : the user still could drag the window but they cannot leave the
window(frame) until that window was closed (use dispose() method).