Java – identify swing components on specific screen coordinates? (and manually schedule mouseevents)

I'm working on some Java applications that are compatible with alternative input devices Unfortunately, the device in question has a Java API and has hardly entered the alpha phase, so it is very poor What I need to do is basically set up an alternative structure to dispatch mouseevents Does anyone know if there is a way to screen coordinates in swing and find the swing components displayed at the top of the screen point?

Solution

In the AWT container, it is called

findComponentAt(int x,int y) 
          Locates the visible child component that contains the specified position

That is, if it's in 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;
  }

Read your questions. May it help you?

If you want to exercise control, use this... Java awt. The robot class is used to control the mouse and keyboard Once controlled, you can perform any type of mouse and keyboard related operations through your Java code This class is usually used for test automation

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>