Listen to JFrame resize events as the user drags their mouse?

You can add a component listener and implement the componentResized function like that: JFrame component = new JFrame(“My Frame”); component.addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent evt) { Component c = (Component)evt.getSource(); //…….. } }); EDIT: Apparently, for JFrame, the componentResized event is hooked to the mouseReleased event. That’s why the method is invoked when the … Read more

How to get location of a mouse click relative to a swing window

From MouseListener methods you can do: @Override public void mouseClicked(MouseEvent e) { int x=e.getX(); int y=e.getY(); System.out.println(x+”,”+y);//these co-ords are relative to the component } Simply add this to your Component by: component.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { } }); Reference: How to Write a Mouse Listener

Javascript: Capture mouse wheel event and do not scroll the page?

You can do so by returning false at the end of your handler (OG). this.canvas.addEventListener(‘wheel’,function(event){ mouseController.wheel(event); return false; }, false); Or using event.preventDefault() this.canvas.addEventListener(‘wheel’,function(event){ mouseController.wheel(event); event.preventDefault(); }, false); Updated to use the wheel event as mousewheel deprecated for modern browser as pointed out in comments. The question was about preventing scrolling not providing the right … Read more

Display mouse coordinates near mouse as hints on mouse move

JFreeChart has quite flexible support for crosshairs. To do what you described I would use an Overlay on the ChartPanel, and update the crosshairs from your ChartMouseListener. Here is a self-contained example (which I’ll add to the collection of demos that we ship with the JFreeChart Developer Guide): package org.jfree.chart.demo; import java.awt.BasicStroke; import java.awt.Color; import … Read more

How to get mouse position in jQuery without mouse-events?

I don’t believe there’s a way to query the mouse position, but you can use a mousemove handler that just stores the information away, so you can query the stored information. jQuery(function($) { var currentMousePos = { x: -1, y: -1 }; $(document).mousemove(function(event) { currentMousePos.x = event.pageX; currentMousePos.y = event.pageY; }); // ELSEWHERE, your code … Read more

Detecting Mouse clicks in windows using python

The only way to detect mouse events outside your program is to install a Windows hook using SetWindowsHookEx. The pyHook module encapsulates the nitty-gritty details. Here’s a sample that will print the location of every mouse click: import pyHook import pythoncom def onclick(event): print event.Position return True hm = pyHook.HookManager() hm.SubscribeMouseAllButtonsDown(onclick) hm.HookMouse() pythoncom.PumpMessages() hm.UnhookMouse() You … Read more