MouseListener on JFrame

I want to receive notifications about mouse events (in particular, about mouse input and exit) on my JFrame. But when I add a mouselistener to it, I get events at the borders of the frame, and not the whole frame with its contents.

Any ideas as to why?

EDIT: Or at least do you have an alternative? I want a “cloudy” way to catch mouse events on a JFrame. Maybe a mouselistener is not the answer.

+5
source share
4 answers

You can get all the events and check if their source is a component in the JFrame.

See Toolkit.addAWTEventListener

+6

, GUI, " ". . :

JFrame frame = new JFrame();
Component glassPane = frame.getGlassPane();
glassPane.addMouseListener(myListener);

, , . :

public void mouseMoved(MouseEvent e) {
    redispatchMouseEvent(e, false);
}
+5

(, JPanel) "" , JFrame.

, . .

+2

AWTEventListener EventQueue. , WebStart .

+2

All Articles