java - Maximizing a JFrame causes MouseMoved events to stop firing -



java - Maximizing a JFrame causes MouseMoved events to stop firing -

it seems maintain finding more issues mousemotion listeners on mac os x. i've made little illustration illustrates problem.

public class testgui extends jframe { panel panel; public testgui() { setsize(1000, 600); setlocationrelativeto(null); panel = new panel(); setdefaultcloseoperation(jframe.exit_on_close); getcontentpane().add(panel); setvisible(true); } class panel extends jpanel { private point mouselocation = new point(); public panel() { addmousemotionlistener(new mouseadapter() { @override public void mousemoved(mouseevent e) { mouselocation = e.getpoint(); repaint(); } }); setvisible(true); } @override protected void paintcomponent(graphics g) { super.paintcomponent(g); g.setcolor(color.black); g.drawstring("(" + mouselocation.x + "," + mouselocation.y + ")", 100, 100); } } public static void main(string[] args) { new testgui(); } }

i'm not sure if happens on windows because don't have access windows computer, on os x next happens:

clicking greenish '+' maximize window causes window maximize, , hence causes mouse pointer in canvas area. if don't click, text says mouse location stop updating.

i know it's not window loosing focus: checked adding focusadapter panel , adding system.out.println() method.

i using jdk 1.7 on mac os x 10.8.5

the answers in this question not work me. matter of fact test case on accepted reply doesn't work on computer.

i can reproduce issue on os x 10.9.3 using jdk1.7.

what see happening when move mouse window decoration bar containing greenish '+' symbol, mouse leaving panel. can seen attaching mouselistener it

public panel() { addmouselistener( new mouseadapter() { @override public void mouseentered( mouseevent e ) { system.out.println( "testgui.panel.mouseentered" ); } @override public void mouseexited( mouseevent e ) { system.out.println( "testgui.panel.mouseexited" ); } } ); addmousemotionlistener(new mouseadapter() { @override public void mousemoved(mouseevent e) { mouselocation = e.getpoint(); repaint(); } }); setvisible(true); }

when press '+' symbol, window indeed maximize causing cursor within panel. however, not mouseentered event. moving mouse not trigger mousemoved event as far swing concerned, mouse hasn't entered component. when moving mouse outside maximised window 1 time again , re-entering, mouseentered event , mousemoved triggered again.

according this question, solved in jdk8. tested on machine, , indeed, switching jdk8 solves issue. if not alternative you, seek utilize workarounds mentioned in other question.

java osx swing mouseevent

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -