Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Ludwig Fischer   on Jun 02 In Java Category.

  
Question Answered By: Ethan Evans   on Jun 02

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).

Share: 

 

This Question has 20 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on jframe not moveable Or get search suggestion and latest updates.


Tagged: