我正在做一些与替代输入设备兼容的
Java应用程序的工作.不幸的是,有问题的设备有一个Java API,现在几乎没有进入alpha阶段,所以很差.我需要做的是基本上设置一个替换结构来分派MouseEvents.有没有人知道在Swing中有没有办法进行屏幕坐标,并找出在该屏幕点顶部显示的Swing组件?
解决方法
在AWT容器中,称之为…
findComponentAt(int x,int y)
Locates the visible child component that contains the specified position
即如果它在Glasspane …
public static Component findComponentUnderGlasspaneAt(Point p,Component top) {
Component c = null;
if (top.isShowing()) {
if (top instanceof RootPaneContainer)
c =
((RootPaneContainer) top).getlayeredPane().findComponentAt(
SwingUtilities.convertPoint(top,p,((RootPaneContainer) top).getlayeredPane()));
else
c = ((Container) top).findComponentAt(p);
}
return c;
}
阅读你的问题,这可能对你有帮助吗?
如果你想锻炼控制使用这个…Java.awt.Robot类用于控制鼠标和键盘.一旦得到控制,您可以通过您的java代码进行与鼠标和键盘相关的任何类型的操作.这个类通常用于测试自动化.