How to get mouse location in NetBeans Visual Library?
-
08-12-2019 - |
Pregunta
I want to add widgets by double clicking, so I've added EditAction to my scene and overrode EditProvider's edit
method. Now the problem is that I want to set initial position of the widget to my mouse position. I've found out that I can use
MouseInfo.getPointerInfo().getLocation()
to get my mouse's location, but it's relative to the screen. I've also read that people use
component.getLocationOnScreen()
to subtract parent's location on screen from the mouse's one, but my scene doesn't seem to implement it.
Solución
After creating a Scene, you need to use createView() (to create the view JComponent) or getView() (to access the already-created JComponent instance).
You can use your JComponent instance (after it is created) to obtain the component's location on screen:
scene.getView().getLocationOnScreen()
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow