java – Dispatch MouseEvent

前端之家收集整理的这篇文章主要介绍了java – Dispatch MouseEvent前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法调度MouseEvent,就像使用dispatchKeyEvent一样
.KeyboardFocusManager.getCurrentKeyboardFocusManager()addKeyEventDispatcher(受听者);
在事件转移到组件之前发生的事情?

我知道我有两个选择

1)将鼠标事件添加到递归的所有组件中

2)使用透明玻璃板

Java支持这个,还是我必须使用上面的选项之一?

谢谢

解决方法

你试过java.awt.Component.dispatchEvent(AWTEvent)吗? @H_502_18@import java.awt.*; import java.awt.event.*; import javax.swing.*; JButton jb = new JButton("Press!"); MouseEvent me = new MouseEvent(jb,// which MouseEvent.MOUSE_CLICKED,// what System.currentTimeMillis(),// when 0,// no modifiers 10,10,// where: at (10,10} 1,// only 1 click false); // not a popup trigger jb.dispatchEvent(me);

猜你在找的Java相关文章