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.

有帮助吗?

解决方案

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()
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top