java – 在特定的屏幕坐标上识别Swing组件? (并手动调度MouseEvents)

我正在做一些与替代输入设备兼容的 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代码进行与鼠标和键盘相关的任何类型的操作.这个类通常用于测试自动化.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...