Generate event, Swing

牧云@^-^@ 提交于 2019-12-11 03:06:04

问题


How can I generate event MouseWheelEvent for some Object?


回答1:


MouseWheelEvent mwe = new MouseWheelEvent(...);
component.dispatchEvent( mwe );



回答2:


You can use Robot class.Take a look at Mouse Wheel method




回答3:


Well, I don't know about generating a scroll Event from an object, but you should take a look at the Robot class. It allows you to actually cause the mouse wheel to scroll. That may be helpful.

Specifically, look at the mouseWheel(int) method.




回答4:


Do you want to actually fire a MouseWheelEvent, or do you want to do something when a mouse wheel is scrolled?

If it is the former you can create a new instance using the constructor:

new MouseWheelEvent(Component source, int id, long when, int modifiers, int x, 
    int y,  int clickCount, boolean popupTrigger, int scrollType, 
    int scrollAmount, int wheelRotation) 

and pass the instance to the component's processMouseWheelEvent method to fire it.

If it's the latter, you can either implement a MouseWheelListener and add it to your component using the addMouseWheelListener() method of Component.



来源:https://stackoverflow.com/questions/2900400/generate-event-swing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!